Reputation: 4087
I have a backend implemented with ASP Web API and, in angularjs, i have injected restangular for crud. So, in the angularjs controller i have:
gestionale.controller('mainController', function ($scope, $http, Restangular) {
var basePersonale = Restangular.all('api/Personale');
basePersonale.getList().then(function (personale) {
$scope.myData = personale;
});
....
....
}
At some point in the controller i need to make a PUT request:
var person = $scope.myData[0];
person.put();
The variable "person" is valued correctly but when is executed the put method i see in the Firefox debugger:
Request method: PUT
Request URL: http://127.0.0.1:49375/api/Personale
Status Code: 405 Method not allowed
and the params of the requested is: {"Id":1,"Nome":"Mat"} and is correct.
In effect that method is not allowed because in the web api the put method respond to this url for example:
// PUT api/Personale/5
Why the request url for the PUT method isn't correct?
Upvotes: 4
Views: 2558
Reputation: 834
If you are using MongoDB you need to tell Restangular that the id field it is expecting is actually _id.
This can be done globally like this:
RestangularProvider.setRestangularFields({
id: "_id"
});
Upvotes: 1
Reputation: 3273
I was having the exact same issue. I realized that I had no 'id' field in my model. I just made sure to set a id (from the mongodb _id) in my instance and now the put route is correct. In your case, you seem to have an Id field, which should be converted to lowercase.
Upvotes: 3