2

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?

Dan M
  • 23
  • 3
  • No idea but I would just start checking out the unminified angular source to see how they define $http and $resource since I think they're probably relevant to your issue. – shaunhusain Jun 29 '13 at 02:39

2 Answers2

4

$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'})
John Oberreuter
  • 271
  • 3
  • 6
  • I finally got around to testing this, and yes it does indeed work...apparently I was spelling 'OPTIONS' wrong when I tried to do it this way and never caught onto it. Thanks! – Dan M Jul 15 '13 at 15:25
0

You can also use $resource:

$resource(address, {}, {options:{method:'OPTIONS'}});
Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
gelmir
  • 1