Hello all,
What I am wanting to do, using the $http service, is to call a
Drupal based service, requesting JSON data in the response. I was looking
at the documentation and it was a bit confusing to me about where the
config object should be defined... I guess that is where you would do this,
right? I'll paste a snippet below and clarify what I want to do. I have a
controller defined in a controllers.js file. I want to replace the get
request that requests a local data.json file (or even a server based
data.json request) with a Drupal data source. My service will return
either xml or json. I want to tell my $http request to send the header
"Accept: application/json". Correct me if I am doing anything else wrong.
So here is my snippet:
var myApp = angular.module('myApp', []);
myApp.controller('MyController', ['$scope', '$http', function($scope,
$http) {
$http.get('js/data.json').success(function(data) {
$scope.artists = data;
});
}]);
So, instead of $http.get("js/data.json"), I want to request
(http://mydrupalsite.com/api/v1/node/) and include in the request the
statement that I want json data. The documentation says:
The $http service will automatically add certain HTTP headers to all
requests. These defaults can be fully configured by accessing the
$httpProvider.defaults.headers configuration object, which currently
contains this default configuration:
- $httpProvider.defaults.headers.common (headers that are common for all
requests):
- Accept: application/json, text/plain, * / *
So, would I add the $httpsProvider.defaults.headers = {"Accept":
"application/json"} just below the
var myApp = angular.module(''myApp', []); and before the controller
definition?
Or does it need to be inside the controller definition.
Thanks in advance for any help,
I hope I was clear,
Bruce
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.