How to design a RESTful collection resource?
- by Suresh Kumar
I am trying to design a "collection of items" resource. I need to support the following operations:
Create the collection
Remove the collection
Add a single item to the collection
Add multiple items to the collection
Remove a single item from the collection
Remove multiple items from the collection
This is as far as I have gone:
Create collection:
==>
POST /service
Host: www.myserver.com
Content-Type: application/xml
<collection name="items">
<item href="item1"/>
<item href="item2"/>
<item href="item3"/>
</collection>
<==
201 Created
Location: http://myserver.com/service/items
Content-Type: application/xml
...
Remove collection:
==>
DELETE /service/items
<==
200 OK
Removing a single item from the collection:
==>
DELETE /service/items/item1
<==
200 OK
However, I am finding supporting the other operations a bit tricky i.e. what methods can I use to:
Add single or multiple items to the collection. (PUT doesn't seem to be right here as per HTTP 1.1 RFC
Remove multiple items from the collection in one transaction. (DELETE doesn't seem to right here either)