The return 204 is pure convention, the code means a successful response with no content (body).
The requisition OPTIONS
itself is a "special" request made by the browser when you request resources from another domain (cross-Domain). Serves to check if you are able to make this request to another domain.
She sends the headers Access-Control-Request-Method
, Access-Control-Request-Headers
and Origin
.
If the server accepts the request, the browser will receive a response containing the headers (prefixed with Access-Control-*
) defining what is available for a particular endpoint.
The name of it is preflight request.
You can see more details on MDN.
In your example, a request with the header Access-Control-Request-Headers
defined as Authorization
and Access-Control-Request-Method
defined as GET
.
The server responded by saying that it is all right (204) and that you can send the header Authorization
that it will be accepted and interpreted, moreover, there is the header Access-Control-Allow-Origin
that defines this endpoint can be called by any source.
"[...] For example, a 204 status code is commonly used with document editing interfaces corresponding to a "save" action, so the document being saved remains available to the user for editing. " - https://httpstatuses.com/204
– Tiago Boeing