204 No Content

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.


HTTP series

This article is part of a series about the HTTP protocol. Read them all here:

Informational 1xx

Successful 2xx

Redirection 3xx

Client Error 4xx

Server Error 5xx

Web mentions