How to get Restangular to PUT without ID?


I’m working on the front-end for a web application that has a somewhat unorthodox “RESTful” back-end. The CRUD actions look like this:

  GET    :id
  POST   {payload}
  PUT    {payload}
  DELETE :id

In other words, the PUT action does not have an ID. Instead, the back-end retrieves the ID from the payload object. This creates a problem when Restangular attempts to generate a URL for a single resource:'model', 2).get().then ($model) ->
  $ = 'newName'

The request then generated by Restangular is, of course:

PUT /model/2

When I actually just need it to be

PUT /model

Is there any programmatically reliable way to accomplish this? It only applies to updating records. Thanks!


You can do it like this:'model').customPUT($model.plain());

With above code and Restangular.service and Restangular.extendModel you can define your own save().

Answered By – tomaszbak

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.