RESTful

面试、写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 |

wiki

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容