Page 2 of 3

Re: using a REST API from JADE

Posted: Thu Mar 08, 2018 1:35 pm
by mike.maynard
Hi Allistar, and thanks for your response.
In an attempt to get this working, I found a free REST based WS to consume.
It is: "http://services.groupkt.com/country/get/iso2code/IN"
and when entered in the browser, shows the following (for code IN, being India):
{
"RestResponse" : {
"messages" : [ "Country found matching code [IN]." ],
"result" : {
"name" : "India",
"alpha2_code" : "IN",
"alpha3_code" : "IND"
}
}
}

So I am trying to use the example that you got working to consume this WS using the JadeHTTPConnection class.
I note the getHttpPageBinary method (I'm in Jade 7.1.05) has an additional parameter to the example, that you have noted, and suspect to be the pServer parameter.

I tried the following, but get no runtime error and status is 0 and result is null. Get same result with null for the last 2 parameters as well.
I suspect there is something pretty obvious that I have missed, or not setup.

From your experience, you might notice the mistake easily ?

My amended code, using the changed endpoint, and GET rather than post, and additional parameter does

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();
result := connection.getHttpPageBinary("GET", null, "http://services.groupkt.com/country/get/iso2code/IN", data, "application/x-www-form-urlencoded").ansiToString();

status := connection.queryStatusCode();
if (status <> 200) then
write "Status="& status.String & " ::Result= "& result;
//handleRequestError(connection, status, result);
endif;

write "Result=" & result;
epilog
delete connection;
end;

Any comment, or you able to paste into jadeScript and try it and let me know where I'm going wrong.
If you can't point me in the right direction I'll talk to the Jade plant.

cheers
Mike

Re: using a REST API from JADE

Posted: Thu Mar 08, 2018 1:52 pm
by allistar
Try this:

Code: Select all

result := connection.getHttpPageBinary("GET", "http://services.groupkt.com", "/country/get/iso2code/IN", "", "application/x-www-form-urlencoded").ansiToString();

Re: using a REST API from JADE

Posted: Thu Mar 08, 2018 2:39 pm
by mike.maynard
Thank you Allistar ..... owe you a drink if you ever run into me :D

Re: using a REST API from JADE

Posted: Mon Apr 09, 2018 11:15 am
by advaro
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.
Hi BeeJay - How are you doing the PUT and DELETE verbs? Is there something in CardSchema that allows these to be done, or some hidden methods or something?
Thanks
Stephen

Re: using a REST API from JADE

Posted: Mon Apr 09, 2018 5:22 pm
by BeeJay
Hi BeeJay - How are you doing the PUT and DELETE verbs? Is there something in CardSchema that allows these to be done, or some hidden methods or something?
Thanks
Stephen
Hi Stephen,

I was just mentioning what I did last time around when I needed to do gets/puts/etc against a 'Web Site' using the TcpIp/JadeHTTP connection classes. Actually, it was the very work to convert the old style News Group messages into these PHP forums, so it's quite a number of years back - Aug 2009 by the looks of the dates on the converted messages. I used Fiddler to trace doing the functions I wanted to do both on these forums and on the old style Jade Newsgroup feeds, to see what the various messages needed to look like etc. I then wrote the code to construct messages in that format both for 'getting' the original messages off the Newsgroup feeds, and the messages for 'putting' the original forum postings into topics on these new style forums.

That may/may not be useful for you with working out the what is required to do similar requests to the REST based web service you're wanting to consume, but hopefully it'll give you some ideas to progress your feature. Alternately, if it's proving too difficult to use from native Jade code, you could take the approach Allistar mentioned whereby you create a wrapper in C# and then use that wrapper from your Jade code by importing your wrapper dll via the External Component Libraries browser in the Jade IDE.

Cheers,
BeeJay.

Re: using a REST API from JADE

Posted: Tue Apr 10, 2018 10:02 am
by allistar
It may be possible to do this in Jade by ignoring the JadeHTTPConnection class and using TcpIpConnection instead. This would likely mean you'd need to replicate a lot of what JadeHTTPConnection is doing. It pains me to have to rely on external libraries for what should be basic functionality. Doing this is a drain on support, debugging and development. All to support very standard HTTP verbs.

Re: using a REST API from JADE

Posted: Tue Apr 10, 2018 10:26 am
by suzuki1100
Try using WinHTTPServices this is effectively what JadeHTTPConnections uses under the hood.
Its and active x automation library

Re: using a REST API from JADE

Posted: Tue Apr 10, 2018 10:31 am
by advaro
Thank you - imported WinHTTPServices yesterday based on one of your previous posts and it works like a charm. Very easy to use, and handles all verbs.
Thanks

Re: using a REST API from JADE

Posted: Thu Jun 28, 2018 10:26 am
by allistar
Hi Troy,
Can you let me know how you imported the WinHTTPServices active x automation library? Is this something you need to install separately or does it come standard with Windows? I can't find anything looking similar in the list.

The lack of PUT and DELETE support in JadeHttpConnection is frustrating. I don't get why there is this arbitrary restriction when under the hood a PUT is pretty much the same as a POST.

Thanks your your help,
Allistar.

Re: using a REST API from JADE

Posted: Thu Jun 28, 2018 11:26 am
by advaro
Hi - we just imported this a couple of months back.
For memory, it doesn't show when you try to import an automation library using a 64bit client. We had to start up a 32bit fat client to see it, then it imported OK.
Private message me if you want, and I can send you the extract of it to save you the hassle if you want.
Stephen