uniform interface:
- resource-based
- Manipulation of Resources Through Representations
- Self-descriptive Messages
- Hypermedia as the Engine of Application State (HATEOAS)
uniform interface:
统一接口约束 定义了客户端和服务端之间的接口,
它简化和结构了架构,使每个部件都能独立发展,
统一接口的四个指导原则:
- resource-based:资源型
使用URI作为资源标识符 在请求中标识各个资源,
资源本身在概念上 与返回给客户端的表示分开,
举例: 服务器不发送其数据库,而是发送一些表示某些数据库记录的 HTML, XML或 JSON
总结起来就是: 使用uri作为资源标识符
uri资源标识符的作用:在请求中标识各个资源。
- Manipulation of Resources Through Representations: 通过表示操控资源
在客户端具有足够的权限,并且 当客户端持有资源的 表示时, 它有足够的信息来修改和删除服务器上的资源。
资源的定义: 比如服务器上的数据库资源
表示的定义: 返回给客户端的数据库几行记录
简单来说:客户端端可以操控服务器上的资源。
- self-descriptive messages: 自我描述信息
每条消息都有足够的信息来描述如何处理消息,
说的就是:
http request:
start line
headers
body
http response:
status line
headers
body
总结起来就是: headers 包含足够信息: 包括 cacheability, media type 等
- Hypermedia AS the engine of Application state: hypermedia 作为应用状态引擎
什么是 hypermedia: 也被成为 hyperlinks (hyperlinks存在于 hypertext中)
具体就是:
Clients deliver state via body contents, query-string parameters, request headers and the requested URI (the resource name). Services deliver state to clients via body content, response codes, and response headers.
http request:
start line
headers
body
http response:
status line
headers
body
uniform interface 总结:
任何REST服务必须提供的统一接口是其设计的基础。
包含4个方面:
uri作为统一资源标识符
客户端具有操控服务端数据的能力,通过接口
通过headers可以携带对消息的完整信息的描述
接口建立在 hypermedia 之上: http request & http reponse
网友评论