204 No Content
204 No Content means the request succeeded and the server intentionally sends no body. It is common for DELETE, for updates that do not echo the resource, and for CORS preflight responses.
The request succeeded and there is deliberately no response body.
Common for DELETE, for PUT or PATCH that do not echo the resource, and for CORS preflight replies. A 204 response cannot carry a body; any bytes the server sends after the headers break the connection framing. Client code that unconditionally parses JSON (await res.json()) throws on a 204, so check the status first.
Explained
A 204 has headers only. The server must not send body bytes; on HTTP/1.1 any extra bytes would be read as the start of the next response on the connection.
The usual client bug is unconditional parsing. In JavaScript, await res.json() on a 204 throws because the body is empty. Check res.status === 204 (or the Content-Length) before parsing.
Choose 200 instead when the client benefits from getting the updated resource back, which saves it a follow-up GET. For a create, 201 with a Location header is more informative than 204.
Gotchas
- Some frameworks still serialize
nulland sendnullas the body of a 204; strict clients and proxies may reject it. - A 204 in response to a browser navigation leaves the current page as it is, which can look like nothing happened.
- Returning 204 for a GET on an empty list is legal but awkward; most APIs return 200 with
[]so clients have one code path.
Related explainers
- 304 Not Modified304 tells the client its cached copy is still good. How ETag and If-None-Match produce it, why it is not...
- 409 Conflict409 means the request clashes with the resource's current state: a duplicate key or a concurrent edit....
- 405 Method Not Allowed405 means the URL exists but rejects that HTTP method. Common causes: missing routes, trailing-slash...