RESTful

2018-05-10  本文已影响141人  Hiapk_Metal

文/Metal(粗略整理)

题引: 在阐述的时候,之前被提问,稍微聊了聊,用自己的理解说说。

正文:

REST:Representational State Transfer //表征性状态传输。太过于术语化。

节选 Dr.Fielding(Roy 坂崎良?)写的。
...."Like most architectural choices, the stateless constraint reflects a design trade-off. The disadvantage is that it may decrease network performance by increasing the repetitive data (per-interaction overhead) sent in a series of requests, since that data cannot be left on the server in a shared context. In addition, placing the application state on the client-side reduces the server's control over consistent application behavior, since the application becomes dependent on the correct implementation of semantics across multiple client versions."

译文:(重要一点)在C-S无状态服务器风格中,有个缺点是,(无状态约束)它可能会通过增加一系列请求中发送的重复性数据(每个交互开销)来降低网络性能,
因为这些数据不能留在共享上下文中的服务器上。

不管怎样去阅读,太过于生涩。

我粗略的理解为,设计成这样为了语义化、可缓存的API。
现如今,Android iOS WebSite 三端都访问Server提供的API,
我们通过这样的设计风格把接口整一套,减少开发成本,一条道地满足三端。
在我们使用场景中,每种客户端来访问Server的时候,假如设计成分层感(分层架构式的样子),
设计起来更加美观。
栗子,摘某友

GET /products :
POST /products :
GET /products/4 :
PATCH/PUT /products/4 :
UPDATE /profile/primaryAddress/city

exp: http://www.havewow/“REST”/heros/2234
可以获得id为“2234”的英雄信息。REST包含(四种操作)
此时情况GET方式。
当然了,还有PUT替换英雄信息
POST 提交 JSON,新增英雄信息
DELETE 删除id=2234的信息。

如此风格,让耳目一新,用起来非常舒适。
综上所述,通俗的理解为,URL定位资源,用四种动作去操作:
GET用来获取资源,
POST用来新建资源(也可以用于更新资源),
PUT用来更新资源,
DELETE用来删除资源。

终,Server快速释放资源(比如返回JSON或XML或。。。),进一步简化实现。

PS:水货码字中,可斧正。

上一篇下一篇

猜你喜欢

热点阅读