What Is a 204 Status Code?
The server has successfully fulfilled the request and that there is no additional content to send in the response payload body.
Metadata in the response header fields refer to the target resource and its selected representation after the requested action was applied.
For example, if a 204 status code is received in response to a PUT request and the response contains an ETag header field, then the PUT was successful and the ETag field-value contains the entity-tag for the new representation of that target resource.
The 204 response allows a server to indicate that the action has been successfully applied to the target resource, while implying that the user agent does not need to traverse away from its current “document view” (if any). The server assumes that the user agent will provide some indication of the success to its user, in accord with its own interface, and apply any new or updated metadata in the response to its active representation.
For example, a 204 status code is commonly used with document editing interfaces corresponding to a “save” action, such that the document being saved remains available to the user for editing. It is also frequently used with interfaces that expect automated data transfers to be prevalent, such as within distributed version control systems.
A 204 response is terminated by the first empty line after the header fields because it cannot contain a message body.
A 204 response is cacheable by default; i.e., unless otherwise indicated by the method definition or explicit cache controls1.
204 CODE REFERENCES
Rails HTTP Status Symbol
Go HTTP Status Constant
Symfony HTTP Status Constant
Python2 HTTP Status Constant
Python3+ HTTP Status Constant
Python3.5+ HTTP Status Constant
Apache HttpComponents Core
204 status code example
Here is an example of a request and response that could result in a 204 status code:
DELETE https://example.com/user/123 HTTP/1.1
Authorization: Bearer <access_token>
HTTP/1.1 204 No Content
Date: Wed, 16 Mar 2023 12:00:00 GMT
In this example, the client is sending a DELETE request to delete a user resource with ID 123 on the
example.com server. The request includes an
Authorization header with an access token to authenticate the request.
The server processes the request successfully and sends a 204 No Content status code in response, which indicates that the request has been successfully processed, but there is no response body to send back to the client. The server does not send any content in the response body because there is no content to send, as the resource has been successfully deleted.
The server also includes a few headers like
Server in the response, which provide additional information about the response. The 204 status code is often used for DELETE requests, where the client wants to delete a resource and does not expect any response content.
What is the difference between a 200 and 204 status code?
The main difference between a 200 and 204 status code is that a 200 status code indicates that the server has successfully processed the request and is returning a response with a message body containing the requested information, whereas a 204 status code indicates that the server has successfully processed the request, but there is no response body to send back to the client.
In other words, a 200 response contains a response body with data, whereas a 204 response does not contain any response body.
Here are some more specific differences between these two status codes:
- A 200 status code is used when the server successfully processes the request and returns a response with a message body containing the requested information. This could include HTML content, JSON data, or any other type of content that the client requested.
- A 204 status code is used when the server successfully processes the request, but there is no content to return to the client. This is typically used for requests where the client wants to indicate that it has finished processing a request, such as a DELETE request.
In general, a 200 status code is used for most types of successful requests, while a 204 status code is used when the server has processed the request successfully, but there is no content to return to the client.
- Learn about web development
- Learn about SEO
- Web development services from WebFX
- SEO services from WebFX
- MDN Web Docs