Rails supports mapping of REST verbs to the controller actions that were historically common in Rails apps when REST support was integrated. In the case of resource collections, these mappings are:
- GET => index
- POST => create
Many collections support "replace all elements with X" semantics. Currently, it is necessary to add a meaningless suffix to any collection URI that needs to support such an operation:
map.resources :tags, :collection => {:blah => :put}
which requires an ugly URL like http://mysite.com/tags/blah.
Similarly, some collections support "delete all elements" semantics and again, an ugly URL is currently required.
This patch adds support for mapping PUT and DELETE against resource collections:
- PUT => replace
- DELETE => obliterate
Now the required URL is purty: http://mysite.com/tags
The replace action would typically expect an array of entities that would completely replace the collection specified in the URI. This interpretation of the PUT operation against a collection of resources is generally accepted and consistent with Rails' existing treatment of POST against a collection and PUT against a member.
The obliterate action would typically destroy all the elements in the collection specified by the URI. Again, this interpretation of DELETE against a collection is generally accepted and consistent with existing Rails' behavior.
References:
- http://www.artima.com/lejava/articles/why_put_and_delete.html
- http://rest.blueoxen.net/cgi-bin/wiki.pl?MinimumMethods#nid5YR