angularjsjsonhttp

Json server update


I'm using json-server and I'm able to do post and get. But I'am not able to do a update.

In my database, I have this data:

{
  "userRecipes": [
    {
      "id": 1,
      "desc": "dog",
      "flag" : true
    }
  ]
}

I wish to update the flag, for doing this I have used this code but it doesn't work:

loginDataSend.flag = true;     
$http
       (
          {
              method: 'update',
 url: 'http://localhost:3000/userRecipes/' + id,
   data: loginDataSend,
   dataType: "json"
    }
   ).error(funcion()
                 {
                 // Error code here
                 alert("error");
                 })
                 .success(function ()
                 {
                 alert("ok");    
                 });

I thank you for your help.


Solution

  • update is not a valid HTTP method.

    You seem to be striving for REST-based API. The REST paradigm is built upon the HTTP protocol and thus there is a inherent mapping between the HTTP Methods you use and the CRUD operations over the entities you want to achieve.

    In HTTP you have the following methods available:

    In your case you should use PUT because you want to make an update.