Angularjs with restangular: invalid PUT url

I have a backend implemented with ASP Web API, and, in angularjs, I introduced restatular for crud. So, in the angularjs controller, I:

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 evaluated correctly, but when the put method is executed, which 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 parameters requested: {"Id": 1, "Nome": "Mat"} and is correct.

In fact, this method is not allowed because in the web api the put method responds to this URL, for example:

// PUT api / Personale / 5

Why is the request URL for the PUT method incorrect?

+4
source share
2 answers

. , "id" . ( mongodb_id) , . , , Id, .

+3

MongoDB, Restangular, id, , _id.

:

RestangularProvider.setRestangularFields({
      id: "_id"
    });
+1

Source: https://habr.com/ru/post/1537736/


All Articles