HTTP 204 No Content: Meaning, Use Cases, and Best Practices
What is HTTP 204 No Content?
The 204 No Content is an HTTP status code that indicates a request succeeded, but the server intentionally returns no message body. The server has successfully processed the requested resource and isn’t returning any content because there’s nothing meaningful to send back.
Think of it like a CI run that ends with “Build succeeded.” The job’s done, everything passed, and there’s nothing more to report.
Unlike redirect codes (301, 302) that send the client to a new URL, 204 is a terminal response that requires no further action. The HTTP response completes immediately without any HTML content or data payload.
A 204 tells the client:
- Your request was successful.
- The operation completed as expected.
- There’s no content to display or process.
Table of Contents
When an operation succeeds but has nothing to say back, that’s where status code 204 comes in. It’s one of the most elegant HTTP status codes, providing a way to say, “I did what you asked, and everything’s fine,” without sending a response payload.
This guide explains what the 204 response code means, when to use it, how it differs from other success codes, and how to test it effectively in Postman.
When to use 204
DELETE requests
When deleting a resource, there’s typically no content response to return:
DELETE /api/users/12345 HTTP/1.1
Authorization: Bearer token123
HTTP/1.1 204 No Content
The resource is gone, and the status code itself confirms success.
PUT and PATCH updates
When updating a resource, if the client already knows the final state, returning it would be redundant:
PUT /api/settings/notifications HTTP/1.1
Content-Type: application/json
{
"email_notifications": false,
"push_notifications": true
}
HTTP/1.1 204 No Content
The client just sent the data, so echoing it back adds no value.
Other common uses
-
Batch operations: Processing multiple items where individual results aren’t needed.
-
Preference updates: User settings and configuration changes.
-
Dismissing notifications: Marking items as read or clearing alerts.
204 vs other success codes
Understanding when to use 204 instead of other 2xx codes is key to good API design.
| Status code | Response body | Use case |
|---|---|---|
| 200 OK | Yes | Successful request with data to return |
| 201 Created | Usually | New resource created |
| 202 Accepted | Usually | Request accepted for async processing |
| 204 No Content | No | Successful request with nothing to return |
204 vs 200 OK
200 OK returns a response body with data. 204 returns no body at all.
Use 200 when the client needs information:
GET /api/users/12345 HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "12345",
"name": "Pat Postman",
"email": "[email protected]"
}
Use 204 when there’s nothing to return, such as after a successful delete request:
DELETE /api/users/12345 HTTP/1.1
HTTP/1.1 204 No Content
204 vs 201 Created
201 Created indicates a new resource was created and typically includes a Location header pointing to it. 204 confirms success without creating anything new.
Use 201 for resource creation:
POST /api/users HTTP/1.1
Content-Type: application/json
{
"name": "Pat Postman",
"email": "[email protected]"
}
HTTP/1.1 201 Created
Location: /api/users/12345
Use 204 for actions that don’t create resources:
DELETE /api/sessions/current HTTP/1.1
HTTP/1.1 204 No Content
204 vs 202 Accepted
202 Accepted means the request was received, but processing has not yet been completed. 204 means processing is complete and successful.
Use 202 for asynchronous operations:
POST /api/reports/generate HTTP/1.1
HTTP/1.1 202 Accepted
Content-Type: application/json
{
"status": "processing",
"check_url": "/api/reports/789/status"
}
Use 204 when the operation completes immediately:
PATCH /api/settings HTTP/1.1
Content-Type: application/json
{
"timezone": "America/Los_Angeles"
}
HTTP/1.1 204 No Content
Real-world examples
E-commerce
-
POST /cart/items→ Add item to cart (might use 204 if cart state is managed client-side) -
DELETE /cart/items/789→ Remove item from cart
Social media
-
POST /posts/456/like→ Like a post -
DELETE /following/789→ Unfollow a user
Task management
-
PATCH /tasks/456→ Mark task as complete -
DELETE /notifications/123→ Dismiss notification
Headers with 204 responses
Even though 204 responses have no body, they can and should include meaningful HTTP headers for caching and rate limiting.
Recommended headers:
HTTP/1.1 204 No Content
Cache-Control: no-cache
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4"
Avoid these:
-
Content-Type: Since there’s no body, content type is meaningless.
-
Content-Length: Should be zero or omitted entirely.
Testing 204 responses in Postman
Postman makes it straightforward to test 204 responses.
Basic test
-
Create a new request in Postman.
-
Set the method to DELETE (or PUT/PATCH).
-
Enter your endpoint URL.
-
Add any required headers or authentication.
-
Click Send.
-
Verify the status shows 204 No Content.
-
Confirm the body is empty.
Writing test scripts
Add automated tests to verify 204 behavior:
pm.test("Status code is 204", function () {
pm.response.to.have.status(204);
});
pm.test("Response has no body", function () {
pm.expect(pm.response.text()).to.equal("");
});
pm.test("Content-Length is zero or absent", function () {
const contentLength = pm.response.headers.get("Content-Length");
if (contentLength) {
pm.expect(contentLength).to.equal("0");
}
});
Mock servers
Create a mock server to simulate 204 responses during development:
-
Create a new collection.
-
Add an example response to your request.
-
Set the status code to 204 No Content.
-
Leave the body empty.
-
Add relevant headers.
-
Create a mock server from the collection.
This lets you develop against the API before the backend is ready.
Best practices
Following these guidelines ensures your API uses 204 appropriately.
When to return 204
Return 204 when:
-
The operation succeeded.
-
There’s genuinely nothing useful to return.
-
The client already knows the outcome.
-
Returning data would be redundant.
When NOT to return 204
Don’t use 204 when:
-
The client needs confirmation details.
-
A new resource was created (use 201).
-
Partial results or status updates are valuable.
-
Error information needs to be conveyed.
Keep responses truly empty
When returning 204, the body must be empty. Don’t send:
❌ HTTP/1.1 204 No Content
Content-Type: application/json
{
"message": "Successfully deleted"
}
This violates the HTTP specification. If you need to send a message, use 200:
✅ HTTP/1.1 200 OK
Content-Type: application/json
{
"message": "Successfully deleted",
"deleted_at": "2024-11-13T10:30:00Z"
}
Be consistent across your API
Establish clear patterns for when you return 204 versus 200. Document these decisions and apply them consistently across all endpoints.
Common mistakes to avoid
Returning a body with 204
The most common mistake is including content in a 204 response. This confuses clients and violates the HTTP specification. If you need to send data, use 200.
Using 204 for errors
Never use 204 for errors or failures. If a resource doesn’t exist, return 404, not 204.
Inconsistent status codes
Don’t alternate between 200 and 204 for the same operation. Pick one and use it consistently.
Overusing 204
Not every successful operation needs a 204. If returning data adds value for the client, use 200:
PATCH /api/users/123 HTTP/1.1
Content-Type: application/json
{
"email": "[email protected]"
}
✅ HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "123",
"email": "[email protected]",
"updated_at": "2024-11-13T10:30:00Z"
}
This confirms the update and shows the new timestamp.
Client-side handling
When your application receives a 204, handle it appropriately.
JavaScript fetch example
fetch('https://example.com/notifications/123/dismiss', {
method: 'DELETE',
headers: {
'Authorization': 'Bearer token123'
}
})
.then(response => {
if (response.status === 204) {
console.log('Notification dismissed successfully');
updateUI();
} else if (response.ok) {
return response.json();
} else {
throw new Error('Request failed');
}
})
.catch(error => {
console.error('Error:', error);
});
Axios example
axios.delete('https://example.com/sessions/current')
.then(response => {
if (response.status === 204) {
console.log('Logged out successfully');
redirectToLogin();
}
})
.catch(error => {
console.error('Logout failed:', error);
});
FAQs
| Question | Answer |
|---|---|
| What does 204 mean? | Request succeeded with no content to return |
| When should I use 204? | For successful DELETE, PUT, or PATCH requests where no data needs to be returned |
| Can 204 have a response body? | No, it must be empty |
| Is 204 an error? | No, it’s a success code (2xx family) |
| Should I use 204 or 200? | Use 204 when there’s nothing to return, 200 when returning data adds value |
The 204 response code communicates success without unnecessary data transfer, reducing bandwidth and simplifying client-side processing. Use it thoughtfully for operations where silence is the best response, ensuring your endpoints remain both performant and semantically correct.
When designing your endpoints, consider what information your clients actually need. Sometimes the most elegant response is no response at all, just a simple 204 to confirm everything worked perfectly.

What do you think about this topic? Tell us in a comment below.