Question

AngularJS' $http service doesn't provide for HTTP Options requests, and I very much would like to have them.

I created a Web API using Django REST framework and I'm trying to leverage all it offers me in an AngularJS web application. My Django REST api provides a plethora of data from HTTP Options requests (e.g. required fields, where to obtain connected data from via hyperlinks, etc.) and I want to leverage that in the Angular application.

However, AngularJS' $http service doesn't appear to support native Options requests which makes this a pretty annoying problem...I mean, if it isn't built-in a workaround isn't going to be pretty.

I tried restangular: definitely not what I need because it doesn't allow me to supply my hyperlinks returned in the JSON from the api, and I'll be darned if I'm parsing a URL for an 'id' - absolutely silly if I have the URL already.

I looked at the angular-django-rest library: highly unsupported and couldn't get PUTs to work for the life of me b/c there's only a $save() method, which somehow automagically selects POST/PUT (?).

So, I'm at a loss! Does anyone have any idea how to get an HTTP Options request in AngularJS?

Was it helpful?

Solution

$http supports options. Options doesn't have a function declared like $http.get() or $http.post(), but you can specify any method you want by specifying the method and passing it directly into $http.

$http({method: 'OPTIONS', url: '/foo'})

OTHER TIPS

You can also use $resource:

$resource(address, {}, {options:{method:'OPTIONS'}});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top