I am trying to expose a REST WEB API as XML, but the result is plain text 

Below the response headers as shown in Chrome

HTTP/1.1 200 OK

Cache-Control: no-cache

Pragma: no-cache

Content-Length: 16091

Content-Type: text/plain; charset=utf-8

Expires: -1

Server: Microsoft-IIS/7.5

Date: Mon, 05 Nov 2018 07:59:03 GMT

Is there a way to expose the result of a REST API as XML instead of text?



Hi Marios,

You can't. The OutSystems REST implementation only works with JSON.

As Kilian said, there is no native way.  You can have an output parameter that returns in the Body and manage the serialization to XML, but your Content-Type will be text/plain.  I attempted to override it by adding an output parameter in the header for Content-Type, but it was still text/plain.  Additionally, if you return Binary Data, the Content-Type will be set to application/octet-stream.

Workaround would be to create a webscreen that returns XML with the appropiate headers.

so, in the preparation logic you end up with a download-widget of the xml.

before that setting the headers correctly etc.

Hi guys,

I've managed to download an XML file, but that is not what I need.

So, the only way to expose XML is through SOAP?



Well, the only way to return a Content-type of application\xml seems to be SOAP, as you cannot change the REST Content-type for some reason (not even in the OnBeforeRequest).


I think the bigger question is why would you want to do this? The standard response for REST calls is JSON. Breaking the standard makes things harder to use and is frankly just odd.  If you really needed to return an XML element as part of the REST structure, you could. On calling it you would need to parse that particular JSON element as XML in whatever you are using to call it

I agree that this is not a requirement that I *personally* see the need for.

That said.

Many REST services I have dealt with do indeed support the ability to request XML output. Clearly someone is using this. I suspect that this is a requirement that comes up far less often due to the widespread adoption of JSON. But in years past, I have personally had to request the XML output of a call due to the options my tools provided me (in those cases, it was the lack of a "JSON Deserialize" built into the platform).