204 No Content
Description
The 204 No Content
status code indicates that the server has successfully processed the request and is not returning any content in the response payload body. The server may return updated metadata in the response headers.
This status code is particularly useful in scenarios where the client only needs confirmation that the request was processed successfully, but doesn't need any content returned. Common use cases include:
- After a successful DELETE operation
- After a successful PUT or PATCH operation where the client already has the updated representation
- For OPTIONS requests to provide communication options
- For form submissions where the user should remain on the same page
The key characteristic of a 204 No Content
response is that it MUST NOT include a message body, and thus no Content-Length or Content-Type header fields should be included.
Syntax
The server responds with a 204 No Content
status without a response body:
Note the absence of Content-Type and Content-Length headers, and the empty line at the end indicating no response body.
Examples
DELETE Operation Example
A client deletes a resource:
Client Request:
DELETE /users/123 HTTP/1.1
Host: api.example.com
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Server Response:
Form Submission Example
A client submits a form that updates user preferences:
Client Request:
POST /preferences HTTP/1.1
Host: app.example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 56
theme=dark¬ifications=weekly&language=en-US
Server Response:
Toggle Operation Example
A client toggles a feature on or off:
Client Request:
PUT /features/dark-mode HTTP/1.1
Host: api.example.com
Content-Type: application/json
Content-Length: 16
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
{"enabled": true}
Server Response:
OPTIONS Request Example
A client checks what methods are allowed on a resource:
Client Request:
Server Response:
HTTP/1.1 204 No Content
Allow: GET, PUT, DELETE, OPTIONS
Access-Control-Allow-Methods: GET, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Summary
The 204 No Content
status code is an efficient way to acknowledge successful request processing without transferring any response body. It reduces bandwidth usage and is particularly valuable in scenarios where the client doesn't need updated content, such as after DELETE operations, certain form submissions, or when toggling settings. By omitting the response body entirely, it provides a clear signal that no content is intended to be returned, rather than indicating an error or empty result.