REST比较准确的定义

REST本身的含义倒是不复杂,但要比较准确地用文字描述出来,倒真不简单了。

Ruby on Rails Guides的解释倒是不错:

Rest stands for Representational State Transfer and is the foundation of the RESTful architecture. This is generally considered to be Roy Fielding’s doctoral thesis, Architectural Styles and the Design of Network-based Software Architectures. While you can read through the thesis, REST in terms of Rails boils down to two main principles:

  • Using resource identifiers such as URLs to represent resources.
  • Transferring representations of the state of that resource between system components.

For example, to a Rails application a request such as this:

DELETE /photos/17

would be understood to refer to a photo resource with the ID of 17, and to indicate a desired action – deleting that resource. REST is a natural style for the architecture of web applications, and Rails hooks into this shielding you from many of the RESTful complexities and browser quirks.

If you’d like more details on REST as an architectural style, these resources are more approachable than Fielding’s thesis:

补充几篇网友的文章:

“如果你想要理解REST,那么你就要转变你的思维,不要再认为以上这些东西都是一张张的网页,让我们以维基百科为例,我查阅的REST词条事实上并不是一张网页,它是一个资源,我们使用http://zh.wikipedia.org/wiki/REST访问这个资源,并取得了它的HTML表示,之所以是HTML,是因为浏览器支持的是这种方式。

我承认这有些费解,http://zh.wikipedia.org/wiki/REST怎 么可能不是网页呢?事实上,确实不是,它是一个使用URL进行标识的资源,当我使用浏览器来访问它时,我得到了它的HTML表示,但维基百科可能还提供其 他形式的表示,比如一个PDF,一张JPG图片或者别的什么东西,而我之所以得到一个HTML,是因为我的Firefox发送了一个GET请求,并明确的 告诉了服务器,给我一个HTML表示。”


可以更费解一些:
http://zh.wikipedia.org/wiki/REST 这个地址代表资源,加上动作”GET", 加上资源表示“HTML”,返回的才是一个网页(网页包括了资源本身和HTML格式);
http://zh.wikipedia.org/wiki/REST 这个地址代表资源,加上动作”GET", 加上资源表示“XML”,返回的才是一个XML文件(资源及XML格式,注意这里格式也是信息或者资源的一部份);
http://zh.wikipedia.org/wiki/REST 这个地址代表资源,加上动作”DELETE“,结果就是删除资源

上述其实包括了三部分的内容或者说两部分的内容HTTP协议(动作,要求的资源表示),资源(这里是URI,类似URL的形式),资源表现形式(XML,HTML),第三个其实是按照封装在HTTP包内的格式要求来选择的。


如果有学习过Rails的话,可以参考 REST on Rails指南5: respond_to   http://blog.csdn.net/dongtg/article/details/2226586 进一步了解 资源表现形式。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值