Restful webservice中的删除操作
我在我的网络服务中遇到了一种情况,我必须删除一个资源并更新使用用户指定的其他资源引用该资源的其他资源。我怎样才能以 RESTful 方式实现这一目标?
例如: 删除资源代理/123 一些客户可能被分配给该代理,因此在删除代理123时,用户将为所有这些客户指定另一个代理125。
我想到了以下方法:
DELETE request on the url Agent/123/125 在服务器上,我将在 url Agent/123 处处理此请求,新的代理 id 将被视为 125。 我觉得这完全背离了 RESTful 方式,所以想放弃这个想法。请告诉我这种方式是否宁静。
另一种选择是: 删除 Agent/123?ReAssignId=125
我不确定这是否也是一种宁静的方式,我在这个 问题。我仍然不相信这个策略。
有没有人遇到过这种情况,应该如何以 Restful 方式处理这种情况?
I've come across a situation in my webservice where in I've to delete a resource and update the other resources which are referring to this resource with other resource specified by user. How can I achieve this in RESTful way?
For example:
DELETE resource Agent/123
Some customers might be assigned to this agent, hence while deleting the Agent 123 user will specify another agent 125 for all these customers.
I thought of following ways:
DELETE request on the url Agent/123/125
On the server I'll handle this request at url Agent/123 and new agent id will be taken as 125.
I felt this is completely away from RESTful way, so thought of dropping this idea. Please let me know whether this restful way.
Another option is:
Delete Agent/123?ReAssignId=125
I'm not sure whether this is also restful way or not, I've come across this method in this question. I'm still not convinced with this strategy as well.
Have any one come across this situation, how this situation should be handled in Restful way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
FWIW,我喜欢选项
Delete Agent/123?ReAssignId=125
因为重新分配编号只是与删除操作关联的元值。核心操作是删除(资源被删除并且不再可用)。FWIW, I like the option
Delete Agent/123?ReAssignId=125
because the reassignment number is just a metavalue associated with the delete operation. The core operation is a delete (resource gets removed and is no longer available).这听起来更像是更新操作和稍后为客户分配新代理时的删除操作。如果这两种方法都必须是原子的,我认为最好的 REST 方式是在客户端上组织它。
This sounds more like an UPDATE operation and a DELETE later on when the new agent has been asigned for the customer(s). If both methods have to be somewhat atomic, I think the best REST-ful way would be to organize this on client.
要真正实现 RESTful,您必须单独更新每个客户资源,然后删除代理。但如果您意识到这更多的是一个指导原则,那么我真的看不出您有什么理由不使用 ReAssignId 技术。
To be truly RESTful, you'll have to individually update each Customer resource, then delete the Agent. But if you've realized that this is all more of a guideline than anything else, I really don't see any reason why you wouldn't use your ReAssignId technique.