How to consume REST web services from a Servoy Solution

Using Servoy to administrate the content of your website? Discuss all webrelated Servoy topics on this forum!

How to consume REST web services from a Servoy Solution

Postby nromeou » Tue Aug 31, 2010 4:40 pm

Hi all,
I'm quite sure somebody has already resolved how to do this.
Could somebody be so kind as to refer me to the info/doc for this issue??

I've read something about using http plugin, but actually is not so simple to use it. :?
I'm having a hard time understanding the methods and I've already search in the wiki for the plugin API but although it was usefull it was not enough.

Thanks for the help
Cheers
nromeou
 
Posts: 215
Joined: Fri Sep 18, 2009 8:38 pm
Location: Montevideo, Uruguay

Re: How to consume REST web services from a Servoy Solution

Postby Jan Aleman » Mon Sep 06, 2010 11:23 pm

So what exactly have you tried so far and what is not working or should be documented in more detail?
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth

Re: How to consume REST web services from a Servoy Solution

Postby swingman » Mon Sep 06, 2010 11:52 pm

Hi,

in earlier versions of Servoy there was no way of fully consuming RESTful web services using the http plugin - the plugin was too limited, it could only POST and GET. So, I had to write my code around these limitations. I have just upgraded to Servoy 5.1.x, and we are still running the old code, so I don't know if this has changed. Since I was also developing the provider of the RESTful web service, I added some extra actions to provide a service that Servoy could consume.

Function to fetch an order:
Code: Select all
var url = globals.aut_web_host() + 'orders_submitted/fetch.xml';
return plugins.http.getPageData(url,'Fetcher');

fetch is my custom action.
globals.aut_web_host() is just a variable which holds the root of the url of the web service I'm accessing.

Then I process the orders in a loop:
Code: Select all
plugins.http.createHttpClient('Fetcher');
do
{
   var xml = get_unprocessed_order();
   var found_order = (xml && xml.substr(0,5) == '<?xml');
   
   if(found_order) {
     process_order(xml); //i parse the xml in here and add new records in Servoy.
   }
   
   databaseManager.saveData();

   //delay to give Rails time to delete order if fetched successfully
   application.sleep(5000);
   
}
while (found_order)

plugins.http.deleteHttpClient('Fetcher');


This is all run inside a batch processor (headless client) on the server.
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1472
Joined: Wed Oct 01, 2003 10:20 am
Location: London

Re: How to consume REST web services from a Servoy Solution

Postby nromeou » Tue Sep 07, 2010 3:04 pm

Thanks for the ideas Christian,

Actually the problem is not fully understanding how the http plugin methods work.

I wasn't able to find any reference as to how to send a GET, or POST, etc to the web service.
I was able to create a web service from my solution, no problems there, is really simple with the provided doc. :D

I look at the API of http plugin but there is no reference to RESTful terms such as GET.
Maybe I don't quite understand the way of consuming a web service, I'm new to this functionalities but it seems quite obvious that there should be a way of telling the service what do I want to do with it, not just call the service and pray to get something useful in return. :?

Hope you understand my problem.

Thanks for the help.
nromeou
 
Posts: 215
Joined: Fri Sep 18, 2009 8:38 pm
Location: Montevideo, Uruguay

Re: How to consume REST web services from a Servoy Solution

Postby pbakker » Thu Sep 09, 2010 9:15 am

Hi,

The HTTP plugin supports post, put and get requests. The GET requests are done using getPageData(), the POST requests can be done using getPoster.doPost and the PUT requests can be done using the put() function.

As the plugin allows only limited control over the body content, and the headers, it's not optimized yet for consuming RESTful webservices just yet.

Full support for all types of requests requestsus control over all the relevant parts of the requests will be added to the plugin in the next major version of Servoy. We will have a look if we can make the updated plugin available once the implementation is done, because most likely, the altered plugin will work with the 5.x branch as well.

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands


Return to Web Development

Who is online

Users browsing this forum: No registered users and 6 guests

cron