给我一个非RESTful设计的例子? [英] Give me a example of non-RESTful design?

查看:59
本文介绍了给我一个非RESTful设计的例子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为 Rails 开发人员,我学到了RESTful"这个词.阅读维基百科后,也这里这里.

I learned the term "RESTful" as a Rails developer. After reading wikipedia, also here and here.

我不明白.在我看来,Rails 只是使用简洁 的方式来描述 URL.在我看来,每个 URI 都是 RESTful,在其设计的范围.

I don't get it. It seems to me, Rails is only using a concise way to describe URLs. It seems to me every URI is RESTful, in it's designed scope.

例如,我认为 GET/delete?student_id=3 是 RESTful 在应用程序本身的范围内.

For example, I think GET /delete?student_id=3 is RESTful in the scope the the application itself.

谁能告诉我它违反了哪个限制?请参考 REST 定义中的限制.

Can anybody tell me which constrict does it violate? Please refer the constrict from the REST definition.

推荐答案

GET 请求应该是 idempotent 并且该请求不应在服务器上留下任何副作用.引用 HTTP 规范 sec 9.1.1:

A GET request should be idempotent and the request should not leave any side-effects on the server. Quoting from the HTTP spec sec 9.1.1:

特别是,约定已经建立,GETHEAD 方法不应该具有执行除检索以外的操作的意义.这些方法应该被认为是安全的".这允许用户代理以特殊方式表示其他方法,例如 POSTPUTDELETE,以便用户知道正在请求可能不安全的操作的事实.

In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.

因此 GET/delete?student_id=3 已经违反了 GET 动词的幂等性假设,因为它会删除服务器上的一条记录.

Therefore GET /delete?student_id=3 already violates the idempotency assumption of the GET verb, since it will delete a record on the server.

RESTful 接口是一个统一接口,换句话说,意味着 GET 应该按照 HTTP 规范的要求运行.这就是规范所说的:

A RESTful interface is a uniform interface, which in other words means that a GET is supposed to behave as required by the HTTP spec. And this is what the spec says:

GET 方法意味着检索任何信息(以实体)由请求 URI 标识.如果 Request-URI 是指对于一个数据生成过程,它是生成的数据作为响应中的实体而不是源文本返回流程,除非该文本恰好是流程的输出.

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.

...

这篇关于给我一个非RESTful设计的例子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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