Can we call an external REST API from custom widget ?
Yes, we can call an external REST API from custom widget. I have done in my custom widget.
For Example the code looks like as below.
FetchData: function () {
var apiUrl = "https://myservername/myApiname/MyMethodName";
var resultDataItems;
$.ajax({
async: false,
type: "GET",
url: apiUrl,
data: {"strParams": strParams},
success: function (result){
resultDataItems = JSON.parse(result);
}
});
}
Now you can bind the result in whatever display component you need in your application , for example Gridview, ListView...
Additionally Add the jquery.min library in your libs folder and reference that in index page.
Thanks @KafilBaig
I did this but I keep getting CORS error which says that
Do I need to set something in WAB or AGOL to remove this error?
Try this it might help in resolving the issue.
windows icon -> Right click -> command prompt(Admin)
In command prompt window the type
C:\Windows\system32>cd .\drivers\etc and enter
C:\Windows\system32\drivers\etc>notepad hosts
A notepad of Hosts opens. Add the dns entry in the file like
10.11.11.11 maps.org.com