I am using
return response(null,204);
because I would like to return an empty body message, but the problem is that when I parse the response with a ruby code
JSON.parse(res.body)
I get some body message:
{"data"=>[]}
so how can I avoid to return this "data" and instead return only the status code?
By default, 204 (No Content) the response is cacheable. If caching needs to be overridden then the response must include cache respective cache headers. For example, you may want to return status 204 (No Content) in UPDATE operations where request payload is large enough not to transport back and forth.
The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.
You can use http_response_code() to set HTTP response code. If you pass no parameters then http_response_code will get the current status code. If you pass a parameter it will set the response code.
The HTTP 204 No Content success status response code indicates that a request has succeeded, but that the client doesn't need to navigate away from its current page. This might be used, for example, when implementing "save and continue editing" functionality for a wiki site.
You can also do return response()->noContent();
Try return Response::make("", 204);
Update: Mark's answer is more up to date:
return response()->noContent()
You may return null:
return response(null, 204);
Edit: I didn't read the question before answering and I notice now that you are already doing this. I recommend you just do an empty / null check on the body in your Ruby code if possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With