Angular.js delete resource with parameter

后端 未结 4 1658
醉酒成梦
醉酒成梦 2021-02-01 17:52

My rest api accpets DELETE requests to the following url

/api/users/{slug}

So by sending delete to a specified user (slug) the user would be de

4条回答
  •  一生所求
    2021-02-01 17:54

    I had this problem for a while I was using a service to add / delete / update categories. While passing in params for get it worked fine but then when deleting it was giving me a ?id=1234 instead of api/resource/1234

    I got around this by making the default param a string.

    ///Controller

    Service.delete({categoryId:id}, function(resp){
      console.log(resp)//whatever logic you want in here 
    });
    

    //SERVICES

    $resource('api/resource/:categoryId', {"categoryId":"@categoryId"}, {
       query:{method:"GET"},
       delete:{method:"DELETE"},
    
    });
    

    Should work and the resulting url will be, originally I had categoryId in the default params as a variable name.

    api/resource/1234 etc
    

提交回复
热议问题