Set HTTP status using pub.flow:setResponseCode

I have a requirement where i have to set different HTTP status codes based on each scenario like 200,201,204 etc., But when I am using this service pub.flow:setResponseCode, its setting the code but not displaying the response data. I have used pub.flow:setResponse2 along with this to set my response data, but its not getting displayed.
When i tried to remove pub.flow:setResponseCode, then my response data is shown but with HTTP status as 200:

PFB where HTTP status code is set but no response is diaplyed:

Could anyone please suggest what has to be done to set both HTTP status as 204 and also display my response data.

Thanks in advance.

That is the correct way to set the http status and response and it works also. What version and fix do you have?


Hi @Aishvarya_Verma,
PFB the details:

Please find below mapping steps:



With that fix level also it works. May be you could try with a simple service to rule out if there is an environment issue or service specific issue.


You might consider using $httpResponse instead. From the docs:

You can set an HTTP response by adding a document reference to the pub.flow:HTTPResponsedocument type in the pipeline of the service and naming the variable as $httpResponse. Using the values set in the $httpResponse, Integration Server sends the response back to the client.

Provides a convenient way to set everything. The docs describe how to use it.

Specifically for 204, that code EXPLICITLY indicates that there is no response data.

HTTP Status 204 (No Content) indicates that the server has successfully fulfilled the request and that there is no content to send in the response payload body.

If you’re using 204, don’t send any response body. If you want to send a response body, use some other 2xx code (but not 205 as that also is a ‘no content’ response code).

Conventionally, you might consider an approach that is common for not found:

  • If a specific record is requested, return 404 not found.
  • If the request usually results in a list of records, but the request/query results in no records, return 200 and an empty array.

Thank you, will check this

Thanks a lot for your response. codes other than 204, 205 gives me both status and response.