【发布时间】:2013-09-12 13:09:39
【问题描述】:
有/group/1 和/group/2,而/item/42 是/group/1 的成员。我想从/group/1 中删除/item/42 并将其放入/group/2。我目前的解决方案是这样的:
GET /group/1/item/42 => Get the item from the first group
POST /group/2/item => Create a clone of the item in the 2nd group
DELETE /group/1/item/42 => Delete the original item from the 1st group
这个解决方案有(至少)两个严重的问题:
- 如果客户端在
DELETE之前停止,则该项目将成为两个组的成员。 -
/group/2中的项目 ID 不会相同,这看起来好像项目将失去其身份。
如果我想在一个步骤中更改项目的组成员身份(如果可能,保留其身份),我应该如何重新设计 API?
【问题讨论】:
-
组和项之间是否存在一对多或多对多的关系?
-
@supertopi 每个项目都是一个组的成员。组可以包含任意数量的项目,甚至为零。
标签: api rest group-membership