How to run REST API through browser
Hello friends,
I am trying to create REST API in Cache. I am getting a response from postman but when I tried to launch the same URL on the browser, I am getting service unavailable error.
This is my URL
http://localhost:57772/widgetsdirect/rest/Gunwant
Any help is greatly appreciated.
Thanks and Regards,
Gunwant Kapade
Hi @Gunwant Kapade! Looks like you've run out of licenses.
You may try to build the same with IRIS Community version with this example or download IRIS Community here.
What kind of error do you get when you try from a browser.
From a browser URL the method is Get. Is your service Method a Get?
Could also be licensing.
Hi Kenneth,
I am getting service unavailable error.
Thanks,
Gunwant
Hi Gunwant,
can you show us the postman screenshot, and your resthandler class.
It will be much easier for the community to solve your problem with this info, than having to guess,
Friendly Regards
Sure Danny, I will do that.
This is my REST Class
Class GSK.Rest1 Extends %CSP.REST
{
Parameter HandleCorsRequest = 1;
XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
<Route Url="/:name" Method="GET" Call="Test" Cors="true"/>
</Routes>
}
ClassMethod Test(name as %String) As %Status
{
w "Hello World "_name
Quit $$$OK
}
}
}
I am expecting result like " Hello World Gunwant" from browser ( localhost:57772/widgetsdirect/rest/Gunwant)
From Postman I am getting same result. But from browser service unavailable error I am getting.
Thanks,
Gunwant
It is most likely that you are trying to do a POST but by default the browser is invoking a GET. An alternative to POSTMAN is Advanced REST Client for Chrome which can be invoked from within Chrome or you can download a Windows version as well. It is useful as you can save data to Google Drive and therefore make the data available to other devices that support chrome.
This is my REST Class
Class GSK.Rest1 Extends %CSP.REST
{
Parameter HandleCorsRequest = 1;
XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
}
ClassMethod Test(name as %String) As %Status
{
w "Hello World "_name
Quit $$$OK
}
}
}
I am expecting result like " Hello World Gunwant" from browser ( localhost:57772/widgetsdirect/rest/Gunwant)
From Postman I am getting same result. But from browser service unavailable error I am getting.
Thanks,
Gunwant
Hello Gunwant,
Can we assume that you've set up a Web Application named "/widgetsdirect/rest" via the Management Portal?
I've compiled your code and tested it and it works for me:
Best,
Jean
Hi Jean,
Yes, you are right. I have set up a Web Application named "/widgetsdirect/rest" via the Management Portal, just namespace name is different.
So while running from browser we need any additional settings ?
Thanks,
Gunwant
Hi Gunwant,
I can't think of any additional settings off the top of my head. But here is a link that describes some things that you can try (e.g., making sure "UnknownUser" is enabled and license is all set):
https://community.intersystems.com/post/service-unavailable-while-invoke-rest-url
Hope this helps,
Jean
What does your full URL Map look like?