Muthukumar kr
Muthukumar kr

Reputation: 23

Angularjs $http GET method change to OPTION, while adding custom headers

var users= $resource('http://myapp.herokuapp.com/users', {});
users.get();

After adding header method, http GET method change to OPTION

var users= $resource('http://myapp.herokuapp.com/users', {}, {
    get:{
        method:"GET",
        headers:{'x-access-token':'token'}
    }
});

users.get();

Please guide me why GET method change to OPTION Method.

Upvotes: 2

Views: 1634

Answers (2)

Elankeeran
Elankeeran

Reputation: 6184

Preflight that causes confusion --> Preflight is an additional request the XHR object makes to make sure it's allowed to actually make the request

Check out https://remysharp.com/2011/04/21/getting-cors-working

Upvotes: 0

user12121234
user12121234

Reputation: 2569

Following REST conventions, an OPTION call is being made before the GET call.

To quote the spec:

This method allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.

Upvotes: 1

Related Questions