using a REST API from JADE

For questions and postings not covered by the other forums
mike.maynard
Posts: 8
Joined: Wed Aug 07, 2013 10:36 am

Re: using a REST API from JADE

Postby mike.maynard » Thu Mar 08, 2018 1:35 pm

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

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 1:52 pm

Try this:

Code: Select all

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

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

Re: using a REST API from JADE

Postby mike.maynard » Thu Mar 08, 2018 2:39 pm

Thank you Allistar ..... owe you a drink if you ever run into me :D

advaro
Posts: 19
Joined: Mon Oct 10, 2016 5:59 pm

Re: using a REST API from JADE

Postby advaro » Mon Apr 09, 2018 11:15 am

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

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 » Mon Apr 09, 2018 5:22 pm

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.

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

Re: using a REST API from JADE

Postby allistar » Tue Apr 10, 2018 10:02 am

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.

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

Re: using a REST API from JADE

Postby suzuki1100 » Tue Apr 10, 2018 10:26 am

Try using WinHTTPServices this is effectively what JadeHTTPConnections uses under the hood.
Its and active x automation library

advaro
Posts: 19
Joined: Mon Oct 10, 2016 5:59 pm

Re: using a REST API from JADE

Postby advaro » Tue Apr 10, 2018 10:31 am

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

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 Jun 28, 2018 10:26 am

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.

advaro
Posts: 19
Joined: Mon Oct 10, 2016 5:59 pm

Re: using a REST API from JADE

Postby advaro » Thu Jun 28, 2018 11:26 am

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


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 29 guests

cron