鉴于以下连续收集的书籍:
请求: GET /favorites/books/
响应:
[
{
"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
}
]
更新集合中图书资源位置的最佳方法是什么?
请求: PUT /favorites/books/54
请求正文:
{
"id": "54"
"title": "Ender's Game by Orson Scott Card",
"position": 2
}
答案 0 :(得分:1)
宁静的方法是将职位列表视为资源。
然后你会做类似的事情:
PUT /favorites/books/positions
[
{ "book_id" : "50", "position" : "1"},
{ "book_id" : "54", "position" : "2"},
{ "book_id" : "51", "position" : "3"},
...
]