Restangular uses HTTP OPTIONS instead of GET

Phil

I have an Django application that is exposing data using the Django-rest-framework. I can access my objects in json format like this:

curl http://localhost:8000/cemeteries/

or

curl http://localhost:8000/cemeteries/2/

I am now trying to use AngularJS to access the data.I opted for restangular, which seemed simple enough. I have configured restangular as such:

demoApp.factory('CbgenRestangular', function(Restangular) {
        return Restangular.withConfig(function(RestangularConfigurer) {
            RestangularConfigurer.setBaseUrl('http://localhost:8000');
        });
    });

And then in my controller:

 demoApp.controller('SimpleController', function($scope, simpleFactory, CbgenRestangular, $location){
        $scope.customers = [];

        CbgenRestangular.all("cemeteries/").getList().then(function() {
          console.log("All ok");
        }, function(response) {
          console.log("Error with status code", response.status);
        });

The problem is that in my Django logs, I always see an HTTP OPTIONS request:

[14/Aug/2013 12:24:12] "OPTIONS /cemeteries/ HTTP/1.1" 200 10245

In Firebug it says "Error with status code 0".

Any idea what am I doing wrong? Thanks in advance for your help!

Regards, Phil

Tom Christie

It's possible that the reason you're seeing the OPTIONS request is due to the browser making a pre-flight CORS request. If that is the case you probably want to take a look at https://github.com/ottoyiu/django-cors-headers which is known to play nicely with REST framework.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Restangular: How to get HTTP response header?

Apollo Client sending OPTIONS instead of GET HTTP method

joomla BASE HREF uses HTTP instead of HTTPS

Angular $http is sending OPTIONS instead of PUT/POST

Restangular Multiple IDs in GET

Restangular - get root collection

Html.RenderAction uses Post instead of Get

Why GRPC uses HTTP2 instead of pure TCP?

AngularJS service that uses multiple $http.get

HTTP request from Angular sent as OPTIONS instead of POST

Pre-Flight Http 'OPTIONS' Method being sent instead of 'DELETE'

In HTTP logs I am seeing OPTIONS, GET, OPTIONS, POST why?

Chaining post and get in resolve with Restangular

Why std::get uses template parameter instead of regular parameter?

Android: HttpUrlConnection uses POST to send request bodys (instead of GET)

AJAX in Chrome sending OPTIONS instead of GET/POST/PUT/DELETE?

Why am I getting an OPTIONS request instead of a GET request?

Angular $http sends get instead of post

Migrating from $http to Restangular, tests failing

Sustainsys.SAML2 uses http-redirect instead of http-post

AngularJS $resource makes HTTP OPTIONS request instead of HTTP POST for $save method

How to Get CORS to use HTTP 304 instead of HTTP 200 responses

Cannot get Angular/Restangular form data in Go

Cancelling GET Request to server using Restangular

How to send an array of parameter through GET with Restangular

Restangular GET request returns 100 records only

Angular: HTTP GET request - OPTIONS 405 (Method Not Allowed)

How can I correctly create a WSO2 ESB API that uses HTTPS instead HTTP as protocol?

Sending HTTP request from mobile phone does not work like desktop (sending 'OPTIONS' instead of 'POST)