RESTful level & HATEOAS

RESTful:

Rest is a style of software architecture, design, rather than standard, but provides a set of design principles and constraints. It is mainly used for client and server interaction class software. Based on this style of software can be more concise, more structured and easier to implement caching mechanisms. And to meet these constraints and the application of the principles or design is RESTful.
As shown there are four levels:

 

level 0:The swarmp of POX(Plain old XML)

The starting point of the model is the use of HTTP as a transport system remote interaction, but does not use any mechanism the Web. Basically what you do here is to use HTTP as your own remote interaction mechanism of tunneling mechanisms, usually based on remote procedure calls .

Features:
  1. HTTP only as a communication tunnel (ie, HTTP communication only concerned with the message, rather than focus on behavior between the client and server)

  2. Using remote invocation protocol (Remote Procedure Call Protocol): that is, the client wants to perform a task, or a service request to the server, simply send relevant messages (execution of a handle), without concern for the underlying implementation.

  3. It provides a call interface to the client.

 

Level 1:Resources  

The first step towards glory in the rest RMM is introduced resources. Now, we are beginning to discuss the various resources, instead of sending all requests to a single service endpoint.

Features:
  1. To locate the resource by URI, the independence of resources

  2. It uses "object-oriented" communication mode

Compared to the Level 0, this layer is more mature local client needs to be marked "What do I need?"
 
 

Level 2:HTTP Verbs 

I have used the HTTP POST verb in all interactions 0 and Class 1, but some people use instead of or in addition to use GET GET. At these levels it is not much different, they are used as a tunneling mechanism that allows you to interact through HTTP tunnel. 2 away from this stage, they are as close as possible using HTTP verbs use the HTTP itself.

 
Features:

Level 2追加了HTTP动作来指明我们对于资源要做何种操作,如此,客户端的请求就能完整的表述为“我需要对XX(资源)做XX(行为)”,该层级是当前使用最为广泛地REST层级,通常定义如下四个HTTP动作:

  1. GET—-》一般性获得资源,并不改变资源,所以这种操作相对安全

  2. POST—》通常为创建资源操作

  3. PUT—-》通常为更新资源操作

  4. DELETE-》删除资源操作

同时,服务端不再通过错误消息(当然,某些系统也会封装错误消息,给予客户友善提示)来告诉客户端执行状态,而是通过返回HTTP状态字来告知客户端请求执行结果。

 

Level 3:Hypermedia Controls (超媒体控制)

最后一个级别引入了一些您经常听到的在HATEOAS(超文本作为应用程序状态引擎)的首字母缩写词中提到的内容。它解决了如何从列表中打开插槽到知道如何预约的问题。

特点:
首先要知道HATEOAS (Hypertext As The Engine Of Application State):这种策略解决了我们如何从得到的资源中顺带知晓下一步应当如何进行?因为要服务端的响应要封装“下一步如何做”。
 

层次的意义:

  • Level 1通过使用分而治之来解决处理复杂性的问题,将大型服务端点分解为多个资源。
  • Level 2引入了一组标准动词,以便我们以相同的方式处理类似的情况,消除不必要的变化。
  • Level 3引入了可发现性,提供了一种使协议更加自我记录的方法。

 

HATEOAS

  由上面可知HATEOAS位于第三层。

  HATEOAS即超媒体应用程序状态的引擎,是其余应用程序体系结构的一个组成部分,它区别与其他网络应用程序体系结构。使用HATEOAS,客户端与应用服务器的网络应用程序提供通过超媒体动态信息。REST客户需求没有先验知识如何与应用程序交互或服务器超出一般的超媒体的理解。相比之下,在CORBA客户机和服务器交互通过固定接口共享文档或一个接口描述语言(IDL)。

HATEOAS为RESTful Web服务带来了相同的概念。

当请求资源的某些详细信息时,您将提供资源详细信息以及相关资源的详细信息以及您可以对资源执行的可能操作。例如,在请求有关facebook用户的信息时,REST服务可以返回以下内容

  • 用户详情
  • 获取最近帖子的链接
  • 得到他最近评论的链接
  • 检索他朋友列表的链接。

参考:https://martinfowler.com/articles/richardsonMaturityModel.html

   https://www.cnblogs.com/luv-letter/p/10639945.html

Guess you like

Origin www.cnblogs.com/ren9ie/p/10962540.html