REST API to return without body on 200 OK

I have a requirement for a REST service to return 200 OK without any body attached. By default the flow pipeline is returned, with an empty pipeline returning a body like this:

<BODY bgcolor=#dddddd>
<TABLE bgcolor=#dddddd border=1>
</TABLE>
</BODY>

If I use pub.flow:setResponse2, the smallest responseString I can specify is a single space character - using a null string results in a runtime error. Returning the space character means I am returning a body of size 1 - and I don’t want to return a body at all.

If I set the response code to 204 (No Content), the service returns without a body, which is what I want - except I need to do this for HTTP 200. Is there a way to achieve this?

Is this service pub.flow:setResponseCode not working for you, which will help to set the required response code ?

Hi Michael,

Mostly 200 OK returns if the Rest call is successful. We handle the code to be returned and along with a custom message to override the default behavior. For which we can use pub.flow:setResponseCode. And the body comprises any details related to call like employee details fetched or ID fetched etc. mostly in case of GET method.

For your case, you aren’t looking for returning any body in response. But Integration Server by default uses the content-type from Accept header field coming in the request to form the response. and it supersedes with Content-Type as text/html. So any system handling your response if they do HTML decode the response they will find nothing i.e. empty response. Without decode, it will show those tags. This is the default behavior of content-handlers in the Integration Server for HTTP responses. you can refer to the Integration Server Administrator Guide for the same.

I still tried and got a result as you need, if you are willing to try then you can do this.

Using pub.flow:setResponse ( deprecated one ), you just do below for variables

  • Just initialize responseString var, do not pass space or something.
  • And for contentType var, you canexplicitly type in as - text/plain

This way you are getting 200 OK without any HTML tags, as the content-Type we used is text/plain.

Unfortunately pub.flow:setResonse2 mandates valid value in responseString or responseBytes either one of this.

These are my findings. I would still recommend either send a body or get it decoded at the client end, rather than using the deprecated method.

Regards,
Firoz N

Hi Michael,

Any update post after the Firoz’s solution above? Please post your end result here and closing comments etc…

TIA,
RMG

1 Like

I was trying to avoid pub.flow:setResponseCode because it is deprecated. Unfortunately its replacement (pub.flow:setResponseCode2) behaves differently and doesn’t allow for an empty payload. It does allow an empty payload if the response code is HTTP 204 (No Content) but I have to return HTTP 200.

In the end we’ve gone with the deprecated service.

Thank you all for your comments and suggestions.

Thanks for letting us know about this. Appreciate your update.