204 No Content
The 204 No Content HTTP status code indicates a successful completion of a HTTP request without any message body included.
The server responds with a 204 No Content status code to signify the successful completion of a HTTP request without any message body included.
This response is cacheable by default and includes an ETag header, but the server can provide specific HTTP caching headers to override the default behavior if required.
When receiving a 204 No Content status code, the HTTP response signifies the successful completion of a request such as POST, PUT, or DELETE, where no message body is expected.
Sometimes, instead of a 204 status code, a server may return a 200 OK status code with a Content-Length specifier as 0 to indicate the same scenario. An instance where this can be applied is when a user presses a "Save" button on a form, and the server commits the changes, relying on the client to notify the user of success.
While 204 is suitable for certain operations, there are other more appropriate HTTP status codes, such as 304 Not Modified, which can indicate the absence of a message body, especially in conditional GET requests.
In this example, the client sends XML data to the server, defining a job completion request. The server acknowledges the acceptance of the data and successfully completes the job. As there is no significant data to be returned in the HTTP response, the 204 No Content status code is appropriately used, indicating that there is no message body to accompany the response.
Request:
POST /job HTTP/1.1
Host: www.example.com
Content-Type: application/xml
Content-Length: 67
< ?xml version="1.0" >
< job >
< id>125
< task>G01
< /job >
Response:
HTTP/1.1 204 No Content
The 204 No Content HTTP status code indicates that a successful HTTP request has been completed, but there is no additional information to be sent in the response message body.
It is commonly used when a client sends a request for a specific action, and the server successfully executes it without providing any data to be returned to the client.