Subscribe to PHP Freaks RSS

204 No Content

syndicated from planet-php.net on July 31, 2018

204 No Content should be returned by a server when a request was successful, but there was no response body.



For most APIs, the following two responses are the same:



HTTP/1.1 200 OK
Content-Length: 0


HTTP/1.1 204 No Content


The second format has a slight preference by most API designers. The reason there is a separate status-code, is because the 204 No Content response can signal a hypermedia client to not change the document and just stay on the current ‘view’. For example, a client might ‘save’ a document temporarily and not refresh to a new page.



Personally I have not really seen this behavior, but I can absolutely see this as a real possibility for a true HATEOAS client.



However, most of the time, 204 is simply used as a stand-in for 200 without a response body.



204 No content is sometimes misunderstood by implementors of HTTP APIs to indicate that the target resource ‘no longer has any contents’ after a DELETE request. However, other successful requests that don’t have a response body should also have the 204 No Content status, including PUT and POST.



References