204 No Content

The HTTP 204 status code means a request was successful, and the server doesn’t have a response (payload) body to return.

This status code is useful when clients don’t need or servers don’t have a response body. Some real-life examples:

HTTP spec states that the response is terminated by the first empty line after the header fields. Most HTTP clients indeed ignore the response body upon encountering a 204 No Content response. Despite that, some web servers still include it.

Preflight requests

204 No Content is commonly used as a response to CORS preflight requests. Clients use preflight requests to check if servers can handle actual CORS requests:

Origin: https://example.com
Access-Control-Request-Method: DELETE
Access-Control-Request-Headers: Content-Type

If the server can understand CORS and allows the client to send a DELETE request, for example, it will respond with a 204 No Content and CORS-related headers:

HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE
Access-Control-Allow-Headers: Content-Type
Access-Control-Max-Age: 86400

Interested in no-nonsense technical guides?

No spyware, no promotional emails, or keyword-stuffed junk. I will only send you a single email when I've got something interesting to say. Unsubscribe anytime.

You can also subscribe to the Atom feed (it's like RSS, but better).