Is there a way to add more rest bindings on model then just the four CRUD functions?
var Customer = can.Model({
findAll: 'GET /customer',
findOne: 'GET /customer/{id}',
create: 'POST /customer',
update: 'PUT /customer/{id}',
destroy: 'DELETE /customer/{id}'
//maybeAnOtherMethod: 'PUT /customer/{id}/activate'
}, {
});
The idea behind REST is that you have resources and actions on these resources. The resource itself is described by a URL, the action is described by an http verb.
Hence,
GET
is the action for reading,/customer/{id}
describes the resource you want to load. This is fine. And so, all of your five methods are fine, becausecan.Model
is designed to handle CRUD functionality with a basic REST interface.The problem with the last (commented) one is that you mix the resource and the action inside the url. "activate" is definitely a verb and no resource. Hence it does not belong there, but it should be an http verb. This is why you don't find support for this way of programming a REST interface - simply because it's not REST.
While you could redesign the API to think of
activate
as a resource, it's more likely that a customer's status as activated or not activated is a part of thecustomer
resource. You would use theupdate
method, as you are changing something about the customer. In CanJS, it would look something like this:To cut a long story short: In REST, the urls are all about nouns, the http methods are all about verbs.
Does this help to make things a little bit clearer?