RESTful(Representaitonal State Transfer)是一种代码风格,用于操作互联网资源。
相比传统URL,RESTful在URL中不使用动词,转而用http操作表示对资源进行CRUD操作。
http方法 | 资源操作 | 幂等 | 安全 |
GET | READ(RETRIEVE) | Y | Y |
POST | CREATE | N | N |
PUT | UPDATE | Y | N |
DELETE | DELETE | Y | N |
传统url操作示例:
http: //localhost/usr/select/1 GET READ http: //localhost/usr/insert 或类似
http: //localhost/usr/add
POST CREATE http: //localhost/usr/update POST UPDATE http: //localhost/usr/delete GET/POST DELETE
传统模式问题:语义不明确;扩展性差
RESTFUL特性:
1. HATEOAS Hypertext As The Engine Of Application State
2. 资源有唯一标识符
3. 操作资源不改变标识符,由http操作提供
4. 所有操作都是无状态的
5. 统一资源可有多种表现形式xml、json等
6. 减少了拆装箱操作
RESTFUL风格url操作:
http: //localhost/usr/{id} GET READ http: //localhost/usr POST CREATE http: //localhost/usr PUT UPDATE http: //localhost/usr DELETE DELETE