[How to Expose a REST API] Define content-type in REST service

[How to Expose a REST API] Define content-type in REST service

  
Forge Component
(0)
Published on 2015-05-04 by OutSystems Academy
0 votes
Published on 2015-05-04 by OutSystems Academy

I'm trying to define the content-type of a REST response.

I followed the guide at https://www.outsystems.com/forums/discussion/19342/rest-output-mime-type/ but without success. I always get it as "plain/text".

Also, is there a way to define the content-type per resource instead on the "onResponse" callback? For specific reasons I need the content-type to be different per resource.

update: If I add a header like "content-typeaaa" to "application/json" it is delivered to the client. It seems that the server is always overriding the "content-type" I'm setting.

Thanks

Hi Miguel,


What version of the platform and stack (.Net or JAVA) are you using? So I can test it out and see if there is an issue with it.

But yes, you are supposed to be able to set the header at any point in your service, not only in the OnResponse callback. So if you set inside a specific action it will only affect that one action.


Also regarding "application/json", if your output parameter is a structure or list it will automatically default to type "application/json" instead of plain text. Why do you need to go on the custom way for that one?


Regards,
João Rosado

Hi João,


I didn't notice I got a reply, sorry for coming here so late!

So, regarding your questions:


What version of the platform and stack (.Net or JAVA) are you using? So I can test it out and see if there is an issue with it.

I'm using a personal space with the latest version of the Service Studio. I'm not sure if this is enough information for the case...


Also regarding "application/json", if your output parameter is a structure or list it will automatically default to type "application/json" instead of plain text. Why do you need to go on the custom way for that one?

The project I'm building is to create mock responses for configured services. Basically, the responses will be text written in a text area and is up to the user to define the content-type of the responses. This is not a plain-old-webservice that is generated via structures, records or lists hence I need to set the content-type "manually".
Solution

I just went thru the REST service and noticed that I was adding the header as "Content-type" (lower-case t). As soon as fixed name to "Content-Type" it started to work...

Solution