The 204 No Content status code indicates that the server successfully processed the request, but there is no content to send back in the response body.
A 204 response must not include a message body and should not include Content-Length or Content-Type headers.
// Express.js route returning 204 No Content
app.delete("/api/user/:id", (req, res) => {
res.status(204).send();
// .send() ends the response without sending data
});
The client receives a successful response with status code 204, but no response body is rendered or processed.
// Fetch API handling a 204 response
fetch("/api/files/123", { method: "DELETE" })
.then(response => {
if (response.status === 204) {
console.log("Deleted successfully");
// Remove item from UI instantly
document.getElementById("file-row").remove();
}
});