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.
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:
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:
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.
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.
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.
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.