Reputation: 313
Given the following sequential collection of books:
Request: GET /favorites/books/
Response:
[
{
"id": "50"
"title": "The Hitchhiker's Guide to the Galaxy by Douglas Adams",
"position": 1
},
{
"id": "51"
"title": "1984 by George Orwell",
"position": 2
},
{
"id": "52"
"title": "Dune by Frank Herbert",
"position": 3
},
{
"id": "53"
"title": "Slaughterhouse 5 by Kurt Vonnegut",
"position": 4
},
{
"id": "54"
"title": "Ender's Game by Orson Scott Card",
"position": 5
}
]
What would be the best means of updating the position of a book resource in the collection?
Request: PUT /favorites/books/54
Request Body:
{
"id": "54"
"title": "Ender's Game by Orson Scott Card",
"position": 2
}
Upvotes: 2
Views: 290
Reputation: 164
The restful way would be to consider the list of positions as the resource.
You would then do something like :
PUT /favorites/books/positions
[
{ "book_id" : "50", "position" : "1"},
{ "book_id" : "54", "position" : "2"},
{ "book_id" : "51", "position" : "3"},
...
]
Upvotes: 1