Does a 200 OK
response mandate a response body?
I know that 204
code is for a response for which there is no response body. But what semantics for 200?
The HTTP 200 OK success status response code indicates that the request has succeeded. A 200 response is cacheable by default. The meaning of a success depends on the HTTP request method: GET : The resource has been fetched and is transmitted in the message body.
However, they told me specifiying status code like 400, 404, 300, is part of RESTful API, and returning always 200 is the right status code because the server responded and it is alive. APIs, always have to return 200 except 500. Because when the server dies, it can't return anything.
So the answer is: There are no differences is if the response shows with OK or something other, or nothing. 200 means OK and this the most important information. Status message is only human readable transcription of 200 and it is not important for browser.
HTTP Status Code 200: The "OK" ResponseAn HTTP status code 200 means success. The client has requested documents from the server. The server has replied to the client and given the client the documents.
From RFC 7231 6.3.1. 200 OK
Aside from responses to CONNECT, a 200 response always has a payload, though an origin server MAY generate a payload body of zero length. If no payload is desired, an origin server ought to send 204 (No Content) instead.
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