Search code examples
javascriptangularjsrestangular

modify resource using restangular by making put on name not id


I have profile resource which has

  1. profileName,
  2. firstName ,
  3. Lastname and
  4. id

here profileName is unique and used as resource identifier and id is just a count.

To modify resource it accept put request on http://localhost:9090/messanger/api/[profileName]

Now problem is whenever I'm making put request, it replace profile name with id. I am unable to make restangular put request on profileName.

Code is as follows.

$scope.editUser=function(id){
          var profile=$scope.profiles[id];
          $scope.profile=profile;
          profile.save().then(function(res){
              console.log(res);
          });
      }

Solution

  • It turn out that there was a problem with method which was handling put request at backend. Object I was passing has 4 properties in java code but when I was passing it from front end I was passing only 3. Previously I was trying

    var items=Restanular.all("profiles").getList();
    var item=items[i];
    item.propertyName=New Value;
    item.save();
    

    This should have ideally work but I think it require some thing more as when I called save method it made a request on http://localhost:9090/messanger/api/ rather than making request on http://localhost:9090/messanger/api/[profileName]