204 No Content
HTTP response status code 204 No Content is returned by the server to indicate that a HTTP request has been successfully completed, and there is no message body.
A 204 No Content response is cacheable by default and an ETag header is included in this case. If the default behavior needs to be overridden then the response must include the appropriate HTTP caching headers.
Usage
When the 204 No Content status code is received, it is in HTTP response to a HTTP operation such as a POST, PUT, or DELETE, where no message body is expected. In some instances, a server will instead return a 200 OK status code with no message body and a Content-Length specifier as 0.
An example of how this can be used is the result of a HTTP request generated by a user that presses a “Save" button on a form. The server commits the changes and relies on the client informing the user of success.
Depending on the operation, there are other more appropriate HTTP status codes that can be used to indicate there is no message body. For example, a conditional GET might return a 304 Not Modified status code to indicate that the resource does not have to be retrieved, and will not be present in the HTTP response.
Example
In the example, the client posts XML data to the server that defines a job to be complete. The server responds by acknowledging that the data was accepted and the job successfully completed. There is nothing significant to return to the client in the HTTP response, so the 204 No Content status code is appropriate.
Request
POST /job HTTP/1.1
Host: www.example.re
Content-Type: application/xml
Content-Length: 67
<?xml version="1.0">
<job>
<id>125</id>
<task>G01</task>
</job>
Response
HTTP/1.1 204 No Content
Code references
.NET
HttpStatusCode.NoContent
Rust
http::StatusCode::NO_CONTENT
Rails
:no_content
Go
http.StatusNoContent
Symfony
Response::HTTP_NO_CONTENT
Python3.5+
http.HTTPStatus.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
Takeaway
HTTP response status code 204 No Content indicates that a HTTP request has been completed successfully, and any information being returned is in the HTTP headers. No message body will be present.