I am looking for a way to include a default data attribute in an http request. I came up with the following code:
var app = angular.module('dumbhttp', []);
app.service('dumbhttp', function ($http, $location) {
this.post = function(url, data){
data.prePopData = 'sameInfoForEveryRequest';
return $http.post(url, data);
};
});
Although it works, it doesn't feel like the most efficient solution. I have to use the service dumbhttp instead of Angular's $http.
It would be great if something like this could work:
var app = angular.module('$http', []);
app.service('$http', function ($http, $location) {
this.post = function(url, data){
data.prePopData = 'sameInfoForEveryRequest';
return $http.post(url, data);
};
});
Unfortunately, it does not work as expected. Perhaps setting defaults for requests like this could be a better approach:
$http.setDefaluts.requestData.mykey = 'mydefaultvalue'
Just to clarify, I am not using this in a RESTful manner as our team follows a different architecture.
Thank you in advance!
-James