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.
- 1 Calculating Heuristic Freshness RFC7234 Section 4.2.2
- Source: RFC7231 Section 6.3.5
204 CODE REFERENCES
Rails HTTP Status Symbol :no_content
Go HTTP Status Constant http.StatusNoContent
Symfony HTTP Status Constant Response::HTTP_NO_CONTENT
Python2 HTTP Status Constant httplib.NO_CONTENT
Python3+ HTTP Status Constant http.client.NO_CONTENT
Python3.5+ HTTP Status Constant http.HTTPStatus.NO_CONTENT
.NET HttpStatusCode.NoContent
Rust http::StatusCode::NO_CONTENT
Java java.net.HttpURLConnection.HTTP_NO_CONTENT
Apache HttpComponents Core org.apache.hc.core5.http.HttpStatus.SC_NO_CONTENT
Angular @angular/common/http/HttpStatusCode.NoContent
204 status code example
Here is an example of a request and response that could result in a 204 status code:
Request
DELETE https://example.com/user/123 HTTP/1.1
Host: example.com
Authorization: Bearer <access_token>
Response
HTTP/1.1 204 No Content
Date: Wed, 16 Mar 2023 12:00:00 GMT
Server: nginx
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 Date
and 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.
Additional resources
- Learn about web development
- Learn about SEO
- Web development services from WebFX
- SEO services from WebFX
- MDN Web Docs
- W3Schools
Marketing Tips for Niche Industries
- Tourism & Hospitality Statistics
- Travel and Tourism Marketing Budget
- Urgent Care Marketing Ideas: 5 High-ROI Tactics
- WebFX: Your Education Digital Marketing Agency
- Why Auto Part Retailers Need Digital Marketing
- Why Digital Marketing is Essential for Auctioneers
- Your Guide to Digital Marketing for Exercise Equipment Companies
- Your Guide to Digital Marketing for Industrial Repair Companies
- Vision Care Industry Statistics
- 6 Best Heavy Equipment Marketing Agencies