什么是基于 Rest API 的发现 [英] What is discovery based in Rest API

查看:26
本文介绍了什么是基于 Rest API 的发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是基于发现的 REST API?

What is a discovery based REST API?

据我从这个参考资料中了解到的https://en.wikipedia.org/wiki/HATEOAS 基于发现的 REST API 总是提供一个链接到响应中的下一个可能的操作.

From what i can understand from this reference https://en.wikipedia.org/wiki/HATEOAS a discovery based REST API always give a link to the next possible action or actions within the response.

如文章所示,下面的示例是对 HTTP GET 请求的响应.我可以看到下面的代码附加了几个不同的选项,如存款、取款、转账和关闭.

As shown in the article, this below example is a response to a HTTP GET request. I can see that the below code have several different options attached, like deposit, withdraw, transfer and close.

<?xml version="1.0"?>
<account>
   <account_number>12345</account_number>
   <balance currency="usd">100.00</balance>
   <link rel="deposit" href="http://somebank.org/account/12345/deposit" />
   <link rel="withdraw" href="http://somebank.org/account/12345/withdraw" /> 
   <link rel="transfer" href="http://somebank.org/account/12345/transfer" />
   <link rel="close" href="http://somebank.org/account/12345/close" />
 </account>

那么基于发现的 REST API 真的只是关于响应ALSO"给出系统中存在的不同可能性(ofc 仅以正确顺序提及的逻辑可能性)?

So is a discovery based REST API really just all about that the response "ALSO" gives the different posibilities there is in the system (ofc only the logical ones to mention in the correct order) ?

推荐答案

是的,您是对的:在该系统中用于该特定资源.

Yes, you are correct: in that system for that particular resource.

想象一下,在您的示例中,余额为 0 美元,银行政策规定您不能在没有正余额的情况下取款.选项列表中将没有退出"链接.

Imagine in your example the balance is 0 USD and bank policy states you cannot withdraw money without a positive balance. The "withdraw" link would be absent from the list of options.

这篇关于什么是基于 Rest API 的发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆