Exposed API - need to return "Content-Type" as "[text/xml]"

Exposed API - need to return "Content-Type" as "[text/xml]"

  

When someone sends a get request to my exposed API, I want to return a header in the response of "Content-Type" is "[text/xml]" however, the default value I am defining is getting overwritten by outsystems as text/plain. 


To define the header, 

right click on method > new output parameter > Advanced>send in >header >defuault value > "[text/xml]" 

When I send a test from POSTman, I get that the header returned is "Content-Type" "text/plain" which means that my default it not being used, but a header Outsystems has decided on. 

I am new to Outsystems, so please excuse if there is an obvious solution

Hi Johann,

By default, the Content-Type is set based on the Response Format you set for the Exposed REST API. If you want to override it, you need to add an On Before Request and modify the Content-Type to what you want it to be (by iterating over the Headers List).

Hi Kilian, 


Thanks for the response. It does make sense that the type is being automatically assigned the header: "Content-Type" "text/xml" as the thing that I am returning is text.

I just want to see that we are on the same page. The question I had is with regards to an exposed API, not a consumed one. The documentation you pointed me toward is about customizing the header of a response from an API that I may be requesting from. 

I do not see the option to change the headers on the response of my own API that is exposed via OUtsystems. 

https://success.outsystems.com/Documentation/10/Extensibility_and_Integration/REST/Expose_REST_APIs/Customize_REST_API_Responses

This seems to talk about the exposed API, however, it does not seem to have an input for headers. 


I may be misunderstanding your previous answer, please let me know if you understand what I am trying to do. 


Perhaps to make my question more clear. 

This is where I am sitting, looking at. I want to change the header that is currently being sent out. The Header that outsystems defined  I assume is either in the ResponseText or the ResponseBinary. What I would like to know is where it is, and how I can interact with the text in order to edit it. 

Again, very new to Outsystems, so I apologise if this is an obvious question. 

To be super clear. I want to change the Content-Type to the same as the "Accept" "[text/xml]" - so that when I query my API it returns text/xml instead of text/plain. 

Hi Johann,

You are right, in my haste I added the wrong URL. And it indeed seems that it's not possible to alter the header value of Content-Type - I did a few tests, but they all came up empty.

Oh no, that's bad news. Is there any way around this. The application I am making cannot work without it. Any suggestions would be greatly appreciated. My first thought was to try and change the text data type to XML since XML is essentially text, but unfortunately, it is expecting it to be of type text. Are there any external dependencies that allow you to return XML?

Is there perhaps an API proxy that could wrap around the API
and edit the header after it has been sent? For example,
something like Apigee comes to mind. See below. 

Is there something already in Outsystems that could act as an api proxy layer?


Not that I'm aware of, unfortunately.


What are the usual next steps for solving similar such problems? Is there a way I can develop something and publish it to Forge which would allow me to make this change? I am just uncertain how to interact with Outsystems on this level. 

Honostly, I think you're pretty much stuck, unless I've overlooked something. Normally, you'd extend your application using Extensions, but you can't expose a REST API from an Extension, unfortunately. I would advise you to contact OutSystems Support and see if they have a solution (and report back here if they do).

Ok great, 

I have contacted support, I will post the solution if they are able to supply one. 

Thanks for the responses. 

Johann

I have managed to get my API to return "Content-Type" : "text/xml" I will post the method here shortly, however, I am now getting a 406 error which occurs when I add Accept : text/xml to the request to my API. I am not entirely sure why as the content being returned are text/xml and the response from the API contains the header Accept : text/xml - Is this something that I should open a separate question for?


Edit :  have created this as a sperate post here: https://www.outsystems.com/forums/discussion/39715/406-error-during-api-call-when-i-add-accept-text-xml-to-request/#Post143206


The solution below was Kindly provided to me by the Outsystems support team. I was able to replicate this and can confirm that it sent back the Postman reponse.

After this, I, unfortunately, ran into an unexpected 406 error. Which I elaborate on here: https://www.outsystems.com/forums/discussion/39715/406-error-during-api-call-when-i-add-accept-text-xml-to-request/#Post143206 


 We had the chance to look into your sample and the action that you added is in the wrong property. The action to change the header must be in the request not on the response to overwrite the one created automatically by the platform, as described in my solution with your OML in the picture below.



 As you can see, in the call from postman it returns the response in the format that you need.