用于从垃圾箱恢复操作的 RESTful url [英] RESTful urls for restore operation from a trash bin

查看:53
本文介绍了用于从垃圾箱恢复操作的 RESTful url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在实现具有以下操作的 RESTful Web 服务:

I've been implementing a RESTful web service which has these operations:

列出文章:

GET     /articles

删除文章(应该只将选定的文章删除到垃圾箱):

Delete articles (which should remove only selected articles to a trash bin):

DELETE  /articles

列出垃圾箱中的文章:

GET     /trash/articles

我必须实现将文章"从/trash/articles"恢复到/articles"的操作.

问题来了.你通常是怎么做的?我必须使用什么网址?

And here is the question. Ho do you usually do it? What url do I have to use?

我想出了两种方法.第一个是:

I came up to the 2 ways of doing it. The first is:

DELETE  /trash/articles

但感觉很奇怪,用户可以像永久删除它,不要恢复"一样阅读它.

But it feels strange and a user can read it like "delete it permanently, don't restore".

第二种方式是

PUT     /trash/articles

哪个更奇怪,用户会混淆此操作的作用.

Which is more odd and a user will be confused what this operation does.

我是 REST 的新手,所以请建议您通常如何操作.我尝试在 google 中搜索,但我不知道如何正确提问,所以我没有得到有用的东西.

I'm new to REST, so please advice how you do it normally. I tried to search in google but I don't know how to ask it right, so I didn't get something useful.

推荐答案

另一种选择可能是使用查询参数"来定义补充动作/动词"以涵盖您拥有的这种特殊情况"(假设这是不太容易被 HTTP 动词覆盖).例如,这可以通过以下方式完成:

Another option could be to use "query params" to define a "complementary action/verb" to cover this "special condition" you have (given that this is not very easily covered by the HTTP verbs). This then could be done for example by:

PUT/trash/articles?restore=true

这会使 URI 路径仍然抱怨 REST 指南(指的是资源,而不是编码动作"——比如恢复"),并且会改变你想要做的事情的额外语义"(这是一个非常特殊的情况)到查询参数".查询参数"非常常用于在 REST 中过滤"资源,对于这种情况并不多......但鉴于您的要求,这可能是一个合理的假设.

This would make the URI path still complaint with REST guideline (referring to a resource, and not encoding "actions" - like "restore") and would shift the "extra semantics" of what you want to do (which is a very special situation) to the "query parameter". "Query params" are very commonly used for "filtering" resources in REST, not so much for this kind of situation... but maybe this is a reasonable assumption given your requirements.

这篇关于用于从垃圾箱恢复操作的 RESTful url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆