How to design a RESTful collection resource?

Posted by Suresh Kumar on Stack Overflow See other posts from Stack Overflow or by Suresh Kumar
Published on 2010-05-11T12:32:18Z Indexed on 2010/05/11 12:44 UTC
Read the original article Hit count: 346

Filed under:
|

I am trying to design a "collection of items" resource. I need to support the following operations:

  1. Create the collection
  2. Remove the collection
  3. Add a single item to the collection
  4. Add multiple items to the collection
  5. Remove a single item from the collection
  6. 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)

© Stack Overflow or respective owner

Related posts about restful

Related posts about rest