面试、写API,经常会提到这个。不得不说,这是一个会死一片的问题。
翻了下书(Engineering Software as a Service),Fox依旧是给出了一个十分精简的解释。
REST: REpresentational State Transfer. ... Services and APIs that follow this principle are said to be RESTful
The RESTful URI is self-contained, including all the information needed to satisfy that request
In particular, the result of a request, or the information needed to satisfy the request, does not depend on requests that have come before—a good fit to the statelessness of HTTP.
REST是REpresentational State Transfer的缩写。遵守REST的规则的服务或者API被称为RESTful。
大体来说,REST首先要自包含。既满足某次请求的所需的所有信息,都可以从它的有URI得到。
再者,对于任何一次请求,不应该依赖于之前的请求。
以下是例子:
| | | Non-RESTful Site | RESTful Site |
| ----- |:-------------:| -----:|
| 1 | Login to site: | POST /login/dave | POST /login/dave |
| 2 | Welcome page: | GET /welcome | GET /user/301/welcome |
| 3 | Add item ID 427 to cart: | POST /add/427 | POST /user/301/add/427 |
| 4 | View cart: | GET /cart | GET /user/301/cart |
| 5 | Pay: | POST /checkout | POST /user/301/checkout |