Returning different HTTP Status for REST service

Version 10.1

I want to create a REST service that returns the requested data however if data is requested that does not exist I want to return a 404 status. I read in the documentation that the follow happens.

However this does not address my issue. For example I want to provide an endpoint called /customer/ that would return a list of all customers and /customer/12 that return specifically customers 12 data but /customer/13 that does not exist I want to return a 404 as is our standard for REST services. This enables applications to understand by the HTTP status when they have requested data that does not exist (Or that their end point is incorrect but it appears this scenario is already handled).

I can’t find any documentation on how you modify the HTTP status of the response to REST services I have created.
Can you do this within the flow and if so, is this a good idea as I guess the flow may also be called by other sources other than REST or is this something we should be designing and handling within the API Gateway? I have not used the API Gateway yet so I am not sure if I am even looking at the right product for what we want to achieve.


You can do this within the flow using the pub.flow:setResponseCode service at the end. If the requested data does not exist then call this service at the end and set the code to 404.


Thank you for your help.