REST

  
Hi,
Which component should i use for RESTFul Webservices?
http://www.outsystems.com/forge/component/335/webserviceengine-convert-soap-to-xml-json-rest/
http://www.outsystems.com/forge/component/228/restfulwebservice-restful-webservice-supports-xml-and-json/
http://www.outsystems.com/forge/component/422/restwebservices/

Are they compatible with version 8?
Thanks
Hello João,

If you want to integrate with REST APIs, you should read this post to get a feel of how to perform those integrations in the OutSystems Platform (it directs you to appropriate components, and how to use them).

If you want to create REST APIs, the approach will be a bit different. Do you need ideas for this use-case?

Best regards,
Ricardo Silva
Ricardo Silva wrote:
Hello João,

If you want to integrate with REST APIs, you should read this post to get a feel of how to perform those integrations in the OutSystems Platform (it directs you to appropriate components, and how to use them).

If you want to create REST APIs, the approach will be a bit different. Do you need ideas for this use-case?

Best regards,
Ricardo Silva
 Ricardo Silva, hi. Can you send some "tips and tricks" for creating REST APIs inside the plataform. We want to expose some functionalities to another system developed on iOS plataform. We know something that could help us on this? thank
 
Well... There's really not much to it.

What you *really* need is:

1) a webscreen with the anonymous role (so no request fails for not having a session)
2) a preparation on that webscreen which terminates in a download node (with Save to Disk set to false)

Then your API will be a webcall to /eSpaceName/ScreenName.aspx?Parameter1=val&Parameter2=val

Now tips for an implementation:

a) have an action which does the work and just call it from the preparation
b) use XML Records or ardoJSON to process the result into XML or JSON format
c) Leverage SEO rules to make sure your API "looks good" by having pretty URL's:

/eSpaceName/user/1 instead of /eSpaceName/GetUser.aspx?UserId=1

d) use HTTPRequestHandler to gather information from the request, like the raw content of the request, headers, origin, etc.

I have never actually implemented a REST API in OutSystems, but these are the basic building blocks I'd use.

If someone already has implemented something like this, please share your experience on tips and tricks :)
A small note, if you're doing CORS (Cross domain ajax), you'll need to add a header to your response:
"Access-Control-Allow-Origin": "*"
You can add the above header by using the HTTPRequestHandler.AddHeader action.
If you don't add the header, probably your client won't be able to consume the data.

EDIT: Something that you should be aware is that this way you're allowing every domain to consume your service. As a rule on thumb you should use instead of "*" something like "www.outsystems.com".
Ruben -

I manage to forget that roughly 50% of the time I do this... I really hope you guys can make REST as easy as SOAP in the near future, we do a TON of REST integrations.

J.Ja
Hello Guys,

I've been looking all discussions regarding REST API on OutSystems... until I got here.

I have an application and as Rogério said above the intention is to expose data as Json so I can consume it on a mobile app.

I was able to use ardoJSON to expose data as Json, however on my mobile app, using Jquery Ajax request I get the following error: "Request failed: parsererrorError: jQuery1110013818948065418546_1413925165467 was not called"

My request is as following:  

carregarHorariosDia = function (valorDia) {
 
                var url = _urlServico + "listarhorario.aspx"; 
                var prms = { dia: valorDia };
                
                var request = $.ajax({
                    url: url,
                    type: "GET",
                    data: prms,
                    contentType: 'application/json',
                    dataType: 'jsonp',
                    jsonp: 'callback'
                });

I have tried and was not able to find a solution. When I try to access the "service" address on Mozilla Firefox it downloads an aspx file even thought I have set the download node (with Save to Disk set to false).

I don't know if this could be the problem. Any help on this?

Thanks,
Adriane

Hi Adriane,

What content type did you set on the download node? It needs to be setted to "application/json".

That should be your main problem.
Then it will depend on what response you are writing to know if the datatype you set is correct or not. Jsonp in some cases is not what you need.

Regards,
João Rosado
Hi, João,

I did set "application/json" as the content type on my download node. 

As I understand, I am using cross domain request and therefore jsonp is what works, other than that if I use json for example I receive a request error. I just don't know if I was able to follow Ruben's tip to set "Access-Control-Allow-Origin": "*" correctly.

I have services created on .NET and if I use it on my request URL everything works fine. 

Even with the error "Request failed: parsererrorError: jQuery1110013818948065418546_1413925165467 was not called" if I open firebug on firefox the json response is there...

Has anyone been able to consume the REST service created by OS with JQuery mobile apps?

Hi,

The way jsonp works requires the server to answer with a callback around the json, instead of only the json.
Check the examples in http://en.wikipedia.org/wiki/JSONP

Quoting:

"
In this example, the received payload would be:

parseResponse({"Name": "Foo", "Id": 1234, "Rank": 7});
"

(Just noticed that on the wikipedia they also say that the correct content type for jsonp should be application/json-p to work with some browsers ...I actually never used jsonp, only json on ajax requests)


As for the Ruben's tip (what allows you to get the json instad of the callback) you can do it with the HttpRequestHander extension that goes with the platform System Components. The action you want is the AddHeader.


Regards,
João Rosado
Hi João,

I finally found the solution!!!

The correct content-type should be "application-json", no need to change.

As I said before, since I am accessing data on different domains (cross domain) as my JSON Service is on my OS espace and my Jquery Mobile app is on localhost, in order to be able to consume the service data I must use JSONP which was created as a work around for the cross domain problem.

However, the trick is that the service created in OS should return JSONP, which means:

 To make our service return JSONP or more exactly: JSON prefixed with the callback method name we’ll have to get the value of the “callback” query string parameter and append our generated JSON element.

as explained in this link http://blog.alexonasp.net/post/2011/07/26/Look-Ma-I-can-handle-JSONP-(aka-Cross-Domain-JSON)-with-WCF-Web-API-and-jQuery!.aspx

So what I did was to create another input parameter "callback" and append it's value to my TextToBinaryData text wrapping my JSON response like: callback + "(" + OutSystems2JSON + ")"  ...and Voilà! 

That makes the trick to have a service returning JSONP!