I am trying to design a "collection of items" resource. I need to support the following operations:
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:
What is a Resource? REST architecture treats every content as a resource. These resources can be Text Files, Html Pages, Images, Videos or Dynamic Business Data. REST Server simply provides access to resources and REST client accesses and modifies the resources. Here each resource is identified by URIs/ Global IDs.
You would be better off using a non-positional identifier such as a UUID for collection items, to avoid problems such as the url of an item changing when you delete an item that precedes it. (Of course, you can still use itemN
or just N
, as long as the number stays attached to the same item at all times, leaving gaps after deletions, but a UUID is less confusing.)
The collection has the url /service/items/
. Each item has the url /service/items/<id>
.
If you really need bulk deletion capability, provide it through a different, clearly marked API, such as PURGE /service/items.
to add items to the collection, you POST them to the collection's URL (http://myserver.com/service/items
). in your case, you already have a 'multiple items' representation in XML, just POST that.
I don't know a simple way to remove multiple items on a single operation... may you could PUT to the collection's item with a list of id's to retain. the idea being that PUT updates the container, so what's not there is removed. and, i think it's not useful to provide the whole data you want to keep, just the references of the items.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With