using a REST API from JADE

For questions and postings not covered by the other forums
David D
Posts: 8
Joined: Wed Nov 08, 2017 2:50 pm

using a REST API from JADE

Postby David D » Wed Nov 08, 2017 3:06 pm

Has anyone sent a request directly to a REST webservice from JADE.... e.g. accessing the new api.business.govt.nz PPSR web services that are becoming available (they return JSON data).

I don't see how it's possible using the new REST service or the old Web Service Consumer...

Thank you

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: using a REST API from JADE

Postby BeeJay » Wed Nov 08, 2017 4:22 pm

The new REST service in Jade is for use where the Jade side is the "provider" of the REST service. It won't be of any help when you want to consume a 3rd party's REST service from Jade code. Unfortunately, for consuming REST services there's not really an agreed standard which would be the equivalent of the WSDL that we have for SOAP based WebServices. Indeed there are vigorous arguments by some experts around why some of the proposals for standards such as WADL/RSDL are a very bad idea for REST based services. Because we don't have the equivalent of a WSDL, there's not really any way to create an equivalent of the WSDL import to create proxy classes for a REST service to make it easier to consume from Jade code.

Assuming you have access to the full documentation for that REST service, you should be able to use that in conjunction with the relevant tcpip connection classes in RootSchema to perform the appropriate POST/GET/PUT/DELETE requests, and then parse the returned JSON to determine success/failure etc. The new JadeJson class could be useful in helping parse the returned JSON string.

Hope that helps,
BeeJay.

David D
Posts: 8
Joined: Wed Nov 08, 2017 2:50 pm

Re: using a REST API from JADE

Postby David D » Thu Nov 09, 2017 7:45 am

Thanks BeeJay... that was my understanding to. I'll use the TCPIP connection classes as suggested.

allistar
Posts: 156
Joined: Fri Aug 14, 2009 11:02 am
Location: Mount Maunganui, Tauranga

Re: using a REST API from JADE

Postby allistar » Thu Nov 09, 2017 7:51 am

Hi David,
Here's some sample code for accessing a REST endpoint. We use something similar to talk Jade to Jade.

Code: Select all

vars connection: JadeHTTPConnection; data, result: String; status: Integer; begin create connection transient; data := '{"someInput":"someValue"}' result := connection.getHttpPageBinary("POST", "https://domain/endpoint/blah.json", data, "application/x-www-form-urlencoded").ansiToString(); status := connection.queryStatusCode(); if (status <> 200) then handleRequestError(connection, status, result); endif; return result; epilog delete connection; end;
This would provide you with the result of the call. You should handle for common status codes (404, 500 etc). Assuming the result is JSON you'd need to parse this. Doing this in Jade is pretty straight forward, JSON is a simple format.

Hope this helps.
Regards,
Allistar.

David D
Posts: 8
Joined: Wed Nov 08, 2017 2:50 pm

Re: using a REST API from JADE

Postby David D » Thu Nov 09, 2017 10:20 am

Thanks Allistar, that example is nice and simple... I'll have a play.

David D
Posts: 8
Joined: Wed Nov 08, 2017 2:50 pm

Re: using a REST API from JADE

Postby David D » Thu Nov 09, 2017 10:25 am

I just note that the getHttpPageBinary() call is one parameter short, is it missing the server name?

Hi David,
Here's some sample code for accessing a REST endpoint. We use something similar to talk Jade to Jade.

Code: Select all

vars connection: JadeHTTPConnection; data, result: String; status: Integer; begin create connection transient; data := '{"someInput":"someValue"}' result := connection.getHttpPageBinary("POST", "https://domain/endpoint/blah.json", data, "application/x-www-form-urlencoded").ansiToString(); status := connection.queryStatusCode(); if (status <> 200) then handleRequestError(connection, status, result); endif; return result; epilog delete connection; end;
This would provide you with the result of the call. You should handle for common status codes (404, 500 etc). Assuming the result is JSON you'd need to parse this. Doing this in Jade is pretty straight forward, JSON is a simple format.

Hope this helps.
Regards,
Allistar.

David D
Posts: 8
Joined: Wed Nov 08, 2017 2:50 pm

Re: using a REST API from JADE

Postby David D » Thu Nov 09, 2017 10:33 am

also I need to add header info with an "Authorization" detail (as per the insomnia example), how is this added?

Thanks
Attachments
insomniaexample.png
insomniaexample.png (38.58 KiB) Viewed 15320 times

User avatar
suzuki1100
Posts: 29
Joined: Tue Nov 24, 2009 12:00 pm
Location: Auckland

Re: using a REST API from JADE

Postby suzuki1100 » Thu Nov 09, 2017 3:46 pm

Hi David,

We ran into issues using JadeHTTPConnection with the timeout setting not working, we have a Parsys call in for it.
Essentially its a wrapper for WinHttpRequest anyway so we ended up creating a RestServiceConsumer class that uses WinHttpRequest and had utility methods to make RestAPi call setup and request easier. We use SSL certificates so using winhttp we could call SetClientCertificate).
In JEDI you will see an idea (Not mine ) https://jedi.jadeworld.com/hub/#/idea/25 that relates to RestAPI consumption. relating to Jade providing a wrapper class for RestAPI consumption.

I think there is validity to this as a lot of the technical detail could be hidden.

mike.maynard
Posts: 8
Joined: Wed Aug 07, 2013 10:36 am

Re: using a REST API from JADE

Postby mike.maynard » Wed Mar 07, 2018 3:28 pm

I have a similar requirement - accessing/consuming a REST based Web Service from my JADE application.

I've been given an endpoint:
. "/Patients/{PatientId}/Episodes/{EpisodeId}/SimpleMedications/Discharge"

with the request details being

Method URI
GET http://servicebase/Patients/{PatientId} ... /Discharge

I haven't consumed a REST based WebService before (have done SOAP / WSDL), does anyone have an example of how this could work, I presume using JadeHTTPConnection class and method calls - once I have the XML response I can parse that to get what I need.

Any tips, just trying to avoid the hard yards.
cheers
Mike

allistar
Posts: 156
Joined: Fri Aug 14, 2009 11:02 am
Location: Mount Maunganui, Tauranga

Re: using a REST API from JADE

Postby allistar » Thu Mar 08, 2018 11:51 am

Hi Mike,
The code I posted above has worked for us. Jade doesn't currently give us a nice way of setting ad-hoc headers in the request such as for authorisation. For those services that require this we resort to using a small .NET component (which pains me greatly as it's a drain on our productivity).

<rant>Jade need to step up their game on the REST API integration. It is lacking in so many areas and we desperately want to avoid using another framework for this. We end up relying on nasty IIS rewrite rules to make the API we expose appear "standard". It's becoming an embarrassment to us when we deal with third party vendors.</rant>

What error are you getting when you try and consume the endpoint using a JadeHTTPConnection?

Regards,
Allistar.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 10 guests