HTTP - OPTIONS Request Method

About

OPTIONS is a request method used in CORS procedure (ie the the “pre-flight” request) asking the server for the CORS headers, but without data.

Example

// The content type is important to see the options request
fetch('https://jsfiddle.net/echo/jsonp/?data=nico', {
    mode: 'cors',
    headers: {
      'content-type': 'application/json'
    }
  })
  • Open the devtool, you should see on the console, the following error.
Access to fetch at 'https://jsfiddle.net/echo/jsonp/?data=nico' from origin 'https://gerardnico.com' 
has been blocked by CORS policy: 
Response to preflight request doesn't pass access control check: 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

  • And in the network tab, you should see the OPTIONS request.

Chrome Options Request





Discover More
Cors Flowchart
Browser - Cross Origin Resource Sharing (CORS)

Cross-origin resource sharing (CORS) is a mechanism that: * allows a HTTP server * to control the cross-origin requests executed by a browser. In short, a HTTP server may allow or not to receive...
Chrome Devtool Har
HTTP - Request

An HTTP request is a message sent from a client to a server. It's the first part of a fetch, the second being the response. A request message has: a first line called the request...
What are the HTTP Request Methods (Get, Post, Put, )?

The http method is a mandatory header of http request that defines the type of operation. A minimal get request from this page It's used by the web server router to map a request to a function....



Share this page:
Follow us:
Task Runner