Answer
OPTIONS Method
The OPTIONS method returns the HTTP methods that the server supports for the specified URL. It creates read-only requests to the server.
Primary Uses
1. Discover Allowed Methods
CODE
OPTIONS /api/users HTTP/1.1
Host: api.example.com
Response:
Allow: GET, POST, OPTIONS
2. CORS Preflight Requests
Browsers automatically send OPTIONS before cross-origin requests to check if the server allows the actual request method:
CODE
OPTIONS /api/data HTTP/1.1
Origin: https://myfrontend.com
Access-Control-Request-Method: POST
Access-Control-Request-Headers: Content-Type
Response:
Access-Control-Allow-Origin: https://myfrontend.com
Access-Control-Allow-Methods: GET, POST, PUT, DELETE
Access-Control-Allow-Headers: Content-Type
Tip for API Testers
Always use OPTIONS to cross-check what methods are allowed before testing endpoints. This helps avoid 405 Method Not Allowed errors.
In Rest Assured
Java
Response response = given()
.when()
.options("https://api.example.com/users");
System.out.println(response.getHeader("Allow"));
// Output: GET, POST, OPTIONS
