← Back to Chapters

HTTP 204 — No Content

? HTTP 204 — No Content

? Quick Overview

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.

? Key Concepts

  • Request was successful
  • No response body is returned
  • Client should not change the current page
  • Often used for background or silent updates

? Syntax / Theory

A 204 response must not include a message body and should not include Content-Length or Content-Type headers.

? Code Example

? View Code Example
// 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
});

? Live Output / Explanation

The client receives a successful response with status code 204, but no response body is rendered or processed.

? Interactive Example

? report_final.pdf
Status: Waiting for action...
? View Code Example
// 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();
    }
  });

? Use Cases

  • DELETE requests
  • Logout actions
  • Form submissions without UI change
  • Background preference updates

✅ Tips & Best Practices

  • Do not return JSON or HTML with 204
  • Use when client UI should remain unchanged
  • Prefer 200 if response data is needed

? Try It Yourself

  1. Create a DELETE API that returns 204
  2. Handle 204 in frontend fetch logic
  3. Compare behavior with 200 OK