How to use REST with POST?

How to use REST with POST?

  
I'm calling Outsystems REST service from WCF, where I can have 2 types of body format: JSON or XML. OutSystems seem to not recognize any of these, so the parameters come empty.
I have also tried POST with parameters in query string - the same.
Only when I use GET + parameters in query string - I'm receiving the values in the service.
I would think that request bodies and POST method are not supported at all, but I know that OutsystemsNow client uses POST for several calls, and since OutSystems does not recognize query parameters in POST, they must be sent in body (wanted to check those requests in Fiddler, but they seem to be hidden somehow by Android emulator).

Or is it expected name=value pairs? This seems a little unusual when working with services, and I will have hard times making it with WCF (probably easier to build request URL and body manually).

In general, it's difficult to find information on REST in OutSystems here... When I'm using search, I'm getting a lot of unrellevant links (seems like the search goes over all HTML data of pages and also includes partial matches without any prioritization). I remember I saw a couple of articles about REST, but they were so small that I actually learned more by investigating OutsystemsNowService eSpace.
In your request header did you add
"content-type: application/json"

?
Robert, yes, there is a header: Content-Type: application/json; charset=utf-8
Igor

Can you download Postman https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm

Now set the header and make a http post to your server endpoint, e.g https://<SERVER>/<eSpace>/rest/<APIName>/<MethodName>

Make sure you are not using "Record List".

Thanks, Robert,

I've checked it with Postman. When I send values as form-data or as key-value pairs - it's Ok, when I send as JSON (also adding Content-type header) - no values are received.
So I suppose I should try making it as key-value pairs...

But your URL is unusual. As I understand, Outsystems exposes URLs without folders (unless overriden by rewrite), so there is no "rest/<APIName>" part, or what did you mean here? I've created REST by adding web screens under "REST" folder, according to all examples I saw.
.. or maybe it would be easier to get raw content via HttpRequestHandler.GetRequestContent() and than parse the JSON.

APIName is the name of your RESTAPI service! One level above the method (REST Expose Actions)

If you've created your own custom REST methods, then check if you are reading the http POST content!
 
Yes, I have created my own, the service is made in OutSystems, and the client in C# WCF.
"Reding the POST content" - what do you mean? Is it the same as using GetRequestContent(), or maybe something more convenient?
Igor Kirtak wrote:
.. or maybe it would be easier to get raw content via HttpRequestHandler.GetRequestContent() and than parse the JSON.
 You have to use this! otherwise how else are you reading the http post content?

See post how to build your own custom REST methods using web screens http://www.outsystems.com/forums/discussion/7379/howto-build-a-simple-restful-web-service-in-outsystems/ (This is a workaround solution, this is how you would build a custom REST service, prior to v9 )

I highly recommend you use outsystems built REST Expose feature! Easier to use, less problems for you!
Robert,

As I checked with Postman, the post content is successfully parsed to input parameters if it's sent as form-values or key-value pairs. So the problem is in that Outsystems doesn't understand incoming JSON in the body, not that it doesn't attempt to parse the body at all.

Thanks for the hint with "expose REST" - I'd like to try that, but our server has to be upgraded before. If it has the same issue - I'll create the idea to support JSON (and XML) - as this is the most common way of using REST, I think.
Hi Igor,

The new feature has JSON support our of the box, and it is very easy to use.
Here is a topic talking abou the feature. It also has a video showing how to use it with JSON examples.

There is no XML support out of the box (it can be done with Text or Binary Data inputs/outputs), but since nowadays all frameworks/languages have easier ways to consume and produce json than they have to XML it's questionable if creating new services with XML is really necessary.

Regards,
João Rosado
João Rosado wrote:
nowadays all frameworks/languages have easier ways to consume and produce json than they have to XML it's questionable if creating new services with XML is really necessary.
 
 I agree, this is true, however sometimes a business might need to use XML either to support legacy applications or maybe you want schema support or namespace support or maybe you want to provide extra information in the attribute for a specific element? <value nil="true">your value</value>

nil = true means this value is optional and can be left empty!

in JSON, you can not do this!

If you dont need to do this, JSON wins on every level! lighter,  faster, easier to read etc

I have tested the new "Expose REST" functionality, it's good and works with JSON, but now I have the opposite problem with Android application. :) It was using old-style REST before, now it can't work with the new method: the error is about url-encoded body is not supported. Is it possible to make the service support both cases somehow? I will look at if it's possible to change Android call meanwhile.