1

I am using Angular (1) with $resource. One of my API request is failing because a URL param is passed as a request body param instead. Why is this happening?

/** @ngInject */
module.exports = function ($resource, API_URL) {
  return $resource(`${API_URL}/users`, null, {
    deactivateUser: {
      url: `${API_URL}/users/deactivate/:id`,
      method: 'put'
    },
    ...
  })
}

Used here:

User.deactivateUser({id})
adriancarriger
  • 2,970
  • 3
  • 19
  • 26
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805

1 Answers1

2

According to the docs, you should specify {id: '@id'} as a second parameter to $resource function. For non-GET requests this will take id parameter and place it into url string, not request body.

Here is the fiddle for that.

antonama
  • 123
  • 8