HTTP status code 204 “No Content” indicates that the server successfully processed the request but did not return any content. This status is commonly used in the following situations:
-
Confirmation of Deletion: The client sends a request to delete a resource (e.g., a DELETE request), and the server successfully deletes the resource without needing to return any content.
-
Updated Cache: The client sends a conditional GET request (such as a GET request with an If-None-Match header) for a specific version of a resource. The server checks and finds that the client’s cache is up to date, so there is no need to transmit the same content again.
-
Resetting a Form: The client submits a form (e.g., via a POST request), and the server successfully processes the form without needing to return any content, but it may choose to reset the client’s form.
When returning a 204 status code, the server typically does not send a response body but may include valid response headers, such as ETag and Cache-Control. These header fields can be useful for updating the client’s cache entries.
Characteristics of Status Code 204:
- No response body, so the Content-Length header should be 0 or omitted.
- Can include response headers, which may be useful to the client.
- The client should stop processing the request and may close the TCP connection.
For example, when a client sends a conditional GET request and the resource has not changed, the server may return the following response:
HTTP/1.1 204 No Content
Date: Wed, 21 Oct 2015 14:48:00 GMT
Cache-Control: no-cache
In this example, the status code 204 indicates that the server successfully processed the request but did not return any resource content. The Cache-Control response header indicates that the client should not cache this response.