I came up with this question, basically looking for a RESTful way to reorder. I don’t really like any of the answers, so this is what I consider the most RESTful.
To reorder, you can make an order a resource:
/list/order
Then you can perform normal operations on it (for these examples, take a list with 5 elements located in it):
"items":" [ { "id": "A", "name": "Monkey" }, { "id": "B", "name": "Cow" }, { "id": "C", "name": "Horse" }, { "id": "D", "name": "Turkey" }, { "id": "E", "name": "Tasmanian Devil" }, ]
Note that "order" is not included in the response of the resource. It is not needed - the order is implicitly determined by the order in which the elements respond.
GET /list/order
returns a list of item identifiers in the correct order
['A','B','C','D','E']
POST /list/order
with payload ['D','B','C','A','E']
GET /list/order
returns a list of item identifiers in the correct order
['D','B','C','A','E']
It is also obvious that you will return the items in the list in the correct order when you execute GET
on /list
.
GET /list
returns a list of items in the correct order
"items":" [ { "id": "D", "name": "Turkey" }, { "id": "B", "name": "Cow" }, { "id": "C", "name": "Horse" }, { "id": "A", "name": "Monkey" }, { "id": "E", "name": "Tasmanian Devil" }, ]