Path: blob/main/files/en-us/web/http/methods/options/index.md
6532 views
------{{HTTPSidebar}}
The HTTP OPTIONS method requests permitted communication options for a given URL or server. A client can specify a URL with this method, or an asterisk (*) to refer to the entire server.
| Request has body | No |
|---|---|
| Successful response has body | Yes |
| {{Glossary("Safe/HTTP", "Safe")}} | Yes |
| {{Glossary("Idempotent")}} | Yes |
| {{Glossary("Cacheable")}} | No |
| Allowed in HTML forms | No |
Syntax
Examples
Identifying allowed request methods
To find out which request methods a server supports, one can use the curl command-line program to issue an OPTIONS request:
The response then contains an {{HTTPHeader("Allow")}} header that holds the allowed methods:
Preflighted requests in CORS
In CORS, a preflight request is sent with the OPTIONS method so that the server can respond if it is acceptable to send the request. In this example, we will request permission for these parameters:
The {{HTTPHeader("Access-Control-Request-Method")}} header sent in the preflight request tells the server that when the actual request is sent, it will have a {{HTTPMethod("POST")}} request method.
The {{HTTPHeader("Access-Control-Request-Headers")}} header tells the server that when the actual request is sent, it will have the
X-PINGOTHERandContent-Typeheaders.
The server now can respond if it will accept a request under these circumstances. In this example, the server response says that:
{{HTTPHeader("Access-Control-Allow-Origin")}}
: The
https://foo.exampleorigin is permitted to request thebar.example/resources/post-here/URL via the following:
{{HTTPHeader("Access-Control-Allow-Methods")}}
: {{HTTPMethod("POST")}}, {{HTTPMethod("GET")}}, and
OPTIONSare permitted methods for the URL. (This header is similar to the {{HTTPHeader("Allow")}} response header, but used only for CORS.)
{{HTTPHeader("Access-Control-Allow-Headers")}}
:
X-PINGOTHERandContent-Typeare permitted request headers for the URL.
{{HTTPHeader("Access-Control-Max-Age")}}
: The above permissions may be cached for 86,400 seconds (1 day).
Status Code
Both {{HTTPStatus("200")}} OK and {{HTTPStatus("204")}} No Content are permitted status codes, but some browsers incorrectly believe 204 No Content applies to the resource and do not send the subsequent request to fetch it.
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
{{HTTPHeader("Allow")}} header