RESTful 删除策略 [英] RESTful delete strategy
问题描述
假设我有一个资源在调用 delete 时可以有两种不同的行为
Let's say I have a resource that can have two different behaviors when delete is called
- 资源被删除.
- 资源已移至回收站.
如何以符合 REST 的方式对其进行建模?
How would model it in a REST compliant way?
我想到了以下解决方案:
I thought about the following solution:
DELETE /myresource
将资源移动到回收站(默认行为)
moves the resource to the recycle bin (default behavior)
DELETE /myresource?force-delete=true
强制删除资源.
那是否符合 REST 标准?调用DELETE的时候一直没看到URL中的查询参数,可以吗?
Is that REST compliant? I have never seen query parameters in the URL when calling DELETE, is that OK?
推荐答案
纯 REST 策略应该更喜欢不改变的资源.在我看来,您并没有通过附加参数来更改资源,因此对我来说这听起来是个好策略.
A pure REST strategy should prefer non changing resources. In my opinion, you are not changing the resource by appending a parameter, so it sounds like good strategy to me.
如果您要执行相同的操作:
If you were to perform the same action like so:
DELETE /myresource.force
这就像另一种资源,这不是最佳的.
that would act like another resource, which wouldn't be optimal.
这篇关于RESTful 删除策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!