No Content
Production Risk
None. This is a clean and efficient way to signal successful completion of an action that does not require a new view or resource representation.
The server has successfully fulfilled the request and that there is no additional content to send in the response payload body. It is often used for DELETE requests or for updates that do not change the resource's representation.
- 1A user successfully deletes a record from a database via a DELETE request.
- 2A 'save' button is clicked on a settings page, and the server saves the changes without needing to reload the page.
- 3An analytic or tracking event is sent to the server which requires no response body.
A user clicks a 'delete' button on a comment, and the application sends a DELETE request to the server.
DELETE /api/comments/123 HTTP/1.1 Host: example.com
expected output
HTTP/1.1 204 No Content
Fix
Return 204 for DELETE and silent-save operations with no response body
// Express — correct use of 204 No Content
app.delete('/api/comments/:id', async (req, res) => {
await db.comments.delete(req.params.id);
res.status(204).end(); // must call .end() — do NOT send a body
});
app.patch('/api/settings', async (req, res) => {
await db.settings.update(req.user.id, req.body);
res.status(204).end(); // settings saved silently
});
// Client-side: do not try to parse the body of a 204
const response = await fetch(`/api/comments/${id}`, { method: 'DELETE' });
if (response.status === 204) {
// Success — remove the item from the UI
removeCommentFromDOM(id);
}Why this works
204 No Content is the correct response when an action succeeds but there is no meaningful body to return. The HTTP spec forbids including a message body in a 204 response — calling res.end() without res.json() or res.send() ensures this. Clients should branch on the status code (204) rather than trying to parse a body, as doing so will result in a parse error.
✕
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev