Publish rest service with POST parameter from body

1
I've been able to publish a simple rest service using this guide: [http://www.mendix.com/blog/rest-part-ii-publishing-microflows-rest/ However, I've noticed the parameter (in this case it's called 'xml') passed to the rest service is put in the URL. In fiddler the request looks like this: GET http://localhost:8082/rest/DocumentToevoegenService?xml=1234 HTTP/1.1 Host: localhost:8082 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Authorization: Basic ... Connection: keep-alive Is it possible to configure the rest service in a way the parameter xml is not passed in the URL but in the body of the request? I want to send a complete xml document as string. URL's have a maximum length therefore it might not work with a complete xml. In fiddler it would look like this: POST http://localhost:8082/rest/DocumentToevoegenService HTTP/1.1 Content-Type: application/x-www-form-urlencoded Host: localhost:8082 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Authorization: Basic ..... Connection: keep-alive <root><tag1><content>test</content></tag1></root> Update - I've changed the request and fiddler now shows the request body like this : { "xml":" <xml><root></root> " } which is valid json I believe. Also, I've changed the request content type to 'application/json;' When debugging my microflow the input parameter of type DocumentToevoegenParameter (non persistent entity with only one attribute with name 'xml') is instantiated but the xml property is empty. What am I missing?
asked
2 answers
2

Ok, so I've found the answer after diving into the java sources for the rest service.

The RestServiceRequest class has the following method:

private RequestContentType determineRequestContentType(HttpServletRequest request)

This method is only able to detect JSON content if the Content-Type header for the request contains "text/json".

Since I used "application/json" as Content-Type this obviously didn't work, the content-type was internally set to 'OTHER' and it couldn't automatically parse the JSON I send.

answered
0

Hi Thomas,

You should definitly post so much data in the body of the request. But note that this doesn't depend on the published service, but on the client you are using to make the call. The published service is capable of both handling GET and POST requests. I don't know how you are making the call currently, but you should change something there.

Note that the REST module currently doesn't accept XML as input data. If you want to send XML to a Mendix app, just use webservices, the REST module only accepts json, binary, multipart or formdata.

Update

Looks fine. Note that the attribute names are case sensitive. Also, is the attribute visible in the microflow from security perspective?

answered