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:
- A Brief Introduction to REST by Stefan Tilkov
- An Introduction to REST (video tutorial) by Joe Gregorio
- Representational State Transfer article in Wikipedia
- How to GET a Cup of Coffee by Jim Webber, Savas Parastatidis & Ian Robinson
“如果你想要理解REST,那么你就要转变你的思维,不要再认为以上这些东西都是一张张的网页,让我们以维基百科为例,我查阅的REST词条事实上并不是一张网页,它是一个资源,我们使用http://zh.wikipedia.org/wiki/REST访问这个资源,并取得了它的HTML表示,之所以是HTML,是因为浏览器支持的是这种方式。
我承认这有些费解,http://zh.wikipedia.org/wiki/REST怎 么可能不是网页呢?事实上,确实不是,它是一个使用URL进行标识的资源,当我使用浏览器来访问它时,我得到了它的HTML表示,但维基百科可能还提供其 他形式的表示,比如一个PDF,一张JPG图片或者别的什么东西,而我之所以得到一个HTML,是因为我的Firefox发送了一个GET请求,并明确的 告诉了服务器,给我一个HTML表示。”