Rest API statusCode 204 with empty response

We have exposed a rest API with 1 output which in case of errors will contain the errors in a fixed format.
The consumer of the API requests that we send a status code 204 in case the call is succesfull,

As 204 means empty response the consumer does not want to receive any response.
But, becase we have 1 output parameter, Outsystems returns {} which is not an empty response.

Is there a way to return  no response at all (eg override the reponse?)
We looked into the OnResponse handler but that only gives the possibility to change the response content, but the {} remain.

Many thanks in advance.

KR,

Eelco.

Hi,

I guess you are using a structure as output and sending the output in body. Did you try changing the output to text? When I tested it in postman it return nothing


Even when output is structure then we can do below in on response and I get same result in postman.

Hi Eelco,

Why can the consumer not handle {} as empty response?

So if status code is 204 and response is {} than it is an empty response.

Also it is a bit strange to me that a consumer of an API will dictate how an API works, that should be the producer telling the consumer "this is how it works.."

Regards,

Daniel


Hi,

If you get {}, that means the rest webservice returns empty, you can add some logic to your server action for the cases where webservice Rest is called and returns {}.


Hi Eelco, 

Adding to what @Daniel Kuhlmann  has said. 204 is a no content success status response code, Meaning the client should not parse any content being returned. So it should not really matter what you return.

Kind regards,
Robin 

Daniël Kuhlmann wrote:

Hi Eelco,

Why can the consumer not handle {} as empty response?

So if status code is 204 and response is {} than it is an empty response.

Also it is a bit strange to me that a consumer of an API will dictate how an API works, that should be the producer telling the consumer "this is how it works.."

Regards,

Daniel


Hi Daniel,

Thanks for your reply.
I should have mentioned this but our client uses Apigee as API proxy and they cannot process 204 with {}.
I will have a look at the solution of Prasad Rao.

KR,
Eelco


Prasad Rao wrote:

Hi,

I guess you are using a structure as output and sending the output in body. Did you try changing the output to text? When I tested it in postman it return nothing


Even when output is structure then we can do below in on response and I get same result in postman.


Hi Prasad,
Thanks for your reply.

I'll have a look at this proposed solution but I see some downsides:
Changing the output format to text is impacting the swagger which is not what we want.
Also when we use this solution it means that we have to customize this for every service, a standard solution would be more preferable.

KR,
Eelco.

Solution

Hi,

Currently I can only think of this approach to solve your problem.

1. You do not have to change the output datatype. my test with post and return datatype as structure yielded same result. I am not super familiar with swagger so can't comment on that.

2. Yes you might have to add onresponse to all the services you expose but you can always group multiple methods inside one service for example below  I have one service test exposing two methods RESTAPIMethod1 and RESTAPIMethod2 but I have one Onresponse which is generic and checks for empty and set the output message to empty binary and sets the status code or else it will simply return the response from method.

Regards.

Solution

I would consider it a bug that the Platform returns {} if you explicitly empty the response. You could return a space though, perhaps that would fool Apigee?

Prasad Rao wrote:

Hi,

Currently I can only think of this approach to solve your problem.

1. You do not have to change the output datatype. my test with post and return datatype as structure yielded same result. I am not super familiar with swagger so can't comment on that.

2. Yes you might have to add onresponse to all the services you expose but you can always group multiple methods inside one service for example below  I have one service test exposing two methods RESTAPIMethod1 and RESTAPIMethod2 but I have one Onresponse which is generic and checks for empty and set the output message to empty binary and sets the status code or else it will simply return the response from method.

Regards.

Hi Prasad,
We are going for your proposed solution.
Thanks for the help.

KR,

Eelco.