Page 1 of 3

using a REST API from JADE

Posted: Wed Nov 08, 2017 3:06 pm
by David D
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

Re: using a REST API from JADE

Posted: Wed Nov 08, 2017 4:22 pm
by BeeJay
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.

Re: using a REST API from JADE

Posted: Thu Nov 09, 2017 7:45 am
by David D
Thanks BeeJay... that was my understanding to. I'll use the TCPIP connection classes as suggested.

Re: using a REST API from JADE

Posted: Thu Nov 09, 2017 7:51 am
by allistar
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.

Re: using a REST API from JADE

Posted: Thu Nov 09, 2017 10:20 am
by David D
Thanks Allistar, that example is nice and simple... I'll have a play.

Re: using a REST API from JADE

Posted: Thu Nov 09, 2017 10:25 am
by David D
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.

Re: using a REST API from JADE

Posted: Thu Nov 09, 2017 10:33 am
by David D
also I need to add header info with an "Authorization" detail (as per the insomnia example), how is this added?

Thanks

Re: using a REST API from JADE

Posted: Thu Nov 09, 2017 3:46 pm
by suzuki1100
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.

Re: using a REST API from JADE

Posted: Wed Mar 07, 2018 3:28 pm
by mike.maynard
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

Re: using a REST API from JADE

Posted: Thu Mar 08, 2018 11:51 am
by allistar
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.