浏览 6457 次
锁定老帖子 主题:再看REST
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-08-08  
最近在看PM老张的《RESTful Web Services》,重新理解了一遍REST,以前的一些迷雾都变清晰了。

1,什么是REST?
"Representational State Transfer (REST) is a style of software architecture for distributed hypermedia systems
such as the World Wide Web. "

现实社会中的分布式超媒体系统的例子主要为www,但是我们不使用http、不与www交互也能构建遵循REST风格的软件系统。
REST是针对分布式超媒体系统的软件架构风格,这个前提很重要。
一般来说谈到REST风格时都是针对www应用的。

REST strictly refers to a collection of network architecture principles that outline how resources are defined
and addressed.
资源是REST的Central Principle。

"Representational State Transfer is intended to evoke an image of how a well-designed Web application behaves:
a network of web pages (a virtual state-machine), where the user progresses through an application by selecting
links (state transitions), resulting in the next page (representing the next state of the application) being
transferred to the user and rendered for their use."
当浏览器浏览访问一个url资源时,返回的页面即为该url资源的representation,这个representation给浏览器一个state,当
浏览器访问下一个url资源时,浏览器的state就transfer了。

2,REST的特性:
Client-Server: a pull-based interaction style: consuming components pull representations. (Comet不遵守REST)
Stateless: each request from client to server must contain all the information necessary to understand the request,
and cannot take advantage of any stored context on the server. (HTTP cookies不遵守REST)
Cache: to improve network efficiency responses must be capable of being labeled as cacheable or non-cacheable.
Uniform interface: all resources are accessed with a generic interface (例如HTTP GET/POST/PUT/DELETE).
Named resources: the system is comprised of resources which are named using a URL.
Interconnected resource representations: the representations of the resources are interconnected using URLs, thereby
enabling a client to progress from one state to another.
Layered components: intermediaries, such as proxy servers, cache servers, gateways, etc, can be inserted between clients
and resources to support performance, security, etc.

3,,什么是RESTful?
Systems that follow Fielding's REST principles are often referred to as RESTful.
www就是一个RESTful的系统,因为www符合REST架构风格。
我们常说RESTful Rails,指的就是使用REST架构风格来做Rails开发,即使用HTTP动词GET/POST/PUT/DELETE和map.resources来开发
resources.rb是RESTful Rails的实现,参考Rails源码研究之ActionController:八,resources

4,什么是RESTful Web Services?
RESTful Web Services即符合REST架构风格的轻量级Web Services。
RESTful Web Services以及ROA(REST oriented architecture)正是《RESTful Web Services》一书要讲的。
Rails的RESTful Web Services实现

参考资源:
http://en.wikipedia.org/wiki/Representational_State_Transfer
http://rest.blueoxen.net/cgi-bin/wiki.pl?FrontPage
http://www.xfront.com/REST-Web-Services.html
《RESTful Web Services》
   发表时间:2007-08-09  
hideto 写道
Stateless: each request from client to server must contain all the information necessary to understand the request,
and cannot take advantage of any stored context on the server. (HTTP cookies不遵守REST)

此处理解有误,Cookie违反的并不是服务器端无状态的架构约束,因为它是保存在客户端的。Cookie的主要问题有两个:
1. 它并不能准确代表每一次请求的状态,因为它是与一个浏览器实例绑定在一起的,而不是与一次请求绑定在一起的。
2. 它违反了REST在语义可见性方面的架构约束。

详情可以仔细看看Fileding论文中文版的“6.3.4.2 Cookie”小节,里面有很详细的解释。
1 请登录后投票
   发表时间:2007-08-09  
嗯,谢谢老大

另外我也看了些semantic web的东西,web3.0很可能就是semantic web?
1 请登录后投票
   发表时间:2007-08-14  
semantic web是现在学术上很火的一个概念,描绘了一幅美好的未来,但到现在仍然没有一个完整的原型系统。有很多人并不看好这项技术的未来,实际上web 2.0带给我们的semantic我们还没有很好的利用
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics