[英]REST API HATEOAS issue
I am reading about HATEOAS in API response, so I have this case, the user will hit this URL first 我正在阅读有关API响应中的HATEOAS的信息,因此我遇到了这种情况,用户将首先点击该URL
Thank you, 谢谢,
is it valid to return HATEOAS in this case, the links are using GET verb. 在这种情况下返回HATEOAS是否有效,链接使用的是GET动词。
HATEOAS: your guiding principle is "how would I do it in web pages?" HATEOAS:您的指导原则是“我将如何在网页上进行?”
In your case, a simple implementation might be that you have a /payments page, and a number of links (pay with paypal, pay by credit card, etc). 在您的情况下,一个简单的实现可能是您有一个/ payments页面,并且有许多链接(使用paypal进行支付,使用信用卡进行支付等)。 Each of those links would GET
a new web page that had a form on it, that would show the consumer what information was required for that type of payment. 这些链接中的每个链接都会GET
一个新的网页,上面有一个表格,该表格将向消费者显示该类型的付款需要哪些信息。 Those forms might immediately submit the payment (which would probably be a POST, with the form arguments in the content body), or they would link to a confirmation page (GET, with the form arguments appearing as query parameters), which would show the user a summary of the payment, with a confirm button that would do the POST as before. 这些表单可能会立即提交付款(可能是POST,内容正文中带有表单参数),或者会链接到确认页面(GET,表单参数显示为查询参数),该页面将显示向用户提供付款摘要,并带有一个确认按钮,该按钮将像以前一样执行POST。
Building a REST api with HATEOAS is the same thing, designed for an program, rather than a person, to consume. 使用HATEOAS构建REST api是同一件事,旨在供程序而非个人使用。 So your links key would contain endpoints for the forms of the allowed payment methods, and those forms would appear with a links key that connects the form to the payment methods. 因此,您的链接键将包含允许的付款方式形式的端点,并且这些表格将带有将表格连接到付款方式的链接键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.