breakitdown

204 No Content

Answer

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.

204
No Content RFC 9110 §15.3.5

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

Related explainers

← All HTTP status codes