当前位置: 首页 > 工具软件 > Related Links > 使用案例 >

PAYPAL开发--REST API HATEOAS links

葛磊
2023-12-01

以下两个是paypal官方的原文链接:
HATEOAS links
HATEOAS and the PayPal REST Payment API

可以简单的理解:

HATEOAS是一种(Hypermedia as the Engine of Application State)技术,而PayPal 通过 links超链接 和 links 对象的定义,来实现这种技术。
这是一种很人性化的技术,而且 spring 中有更详细的介绍。非常不错。在开放平台的系统中建议使用这种技术。

HATEOAS links

Each API call response includes an array of Hypermedia as the Engine of Application State (HATEOAS) links. HATEOAS enables you to interact and construct an API flow solely through the provided hyperlinks. You no longer need to hard code logic into your client to use our API. We provide HATEOAS links for each call and for transactions within a call, if available.

(Hypermedia as the Engine of Application State)
这个定义有点抽象,也不用去管他。
以上的大致意思是: 我们可以通过接口中的HATEOAS链接,决定下一步该怎么走。这样就可以动态的执行 API FLOW。

先看PAYPAL REST 接口中的案例

The following code shows a sample of HATEOAS links:

{
  "links":[
    {
      "href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-2XR800907F429382MKEBWOSA",
      "rel":"self",
      "method":"GET"
    },
    {
      "href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-2XR800907F429382MKEBWOSA/execute",
      "rel":"update",
      "method":"POST"
    }
  ]
}

然后针对 links 对象的解释:

ElementTypeDescription
hrefstringThe URL of the related HATEOAS link to use in subsequent calls.
relstringThe relationship that this link has to the previous call. For example:
methodstringThe HTTP method required for the related call.

Element为rel的EXAMPLE:
- self. Get details of the current call.
- parent_payment. Get details of the parent payment.
- A related call, such as execute or refund.

HATEOAS and the PayPal REST Payment API

One of the key features of the PayPal REST API is HATEOAS (Hypertext As The Engine Of Application State).

At its core, HATEAOAS provides a way to interact with the REST Payment API entirely through hyperlinks. With each call that you make to the API, we’ll return an array of links that allow you to request more information about a call and to further interact with the API. You no longer need to hard code the logic necessary to use the PayPal REST API.

HATEOAS links are contextual, so you only get the information that is relative to a specific request.

PayPal REST API 的特色之一就是 HATEOAS。
他的核心是:HATEOAS提供了一种通过 hyperlinks 能完整的和 REST Payment API 交互和方法。你的每个请求,都会收到一组超链接,通过他们你可以和 REST Payment API 进一步交互。这样你就不用吧代码写死了。
HATEOAS links 是和上下文相关的,所以你得到的信息只和当前请求相关。

 类似资料: