有没有办法发现 ReST API 的所有端点? [英] Is there a way to discover all endpoints of a ReST API?

查看:39
本文介绍了有没有办法发现 ReST API 的所有端点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能以编程方式发现特定 API 的所有端点.

I'm wondering if its possible to programmatically discover all the endpoints of a particular API.

例如,如果我使用浏览器或 curl 获取此 URL:https://api.twitter.com/1.1/

So for example if I GET this URL with a browser or curl: https://api.twitter.com/1.1/

我可能会得到这样的 JSON 响应:

I might get something like this as a JSON response:

{"TwitterAPI":{
    "version" : 1.1,
    "GET" : {
        "search/" : ["users", "trending"],
        "users/" : ["id", "handle"]
    }
}

当然,Twitter 可以选择发布或不发布这种格式.那么作为一个附带问题,是否有任何 Java 或 Javascript 库可以自动映射和发布您在控制器中创建的 API 路由?

Of course Twitter could choose to publish or not publish this format. So as a side question, are there any libraries for Java or Javascript that will automatically map and publish the API routes you created in your controllers?

推荐答案

没有办法以编程方式发现 REST 服务,因为它们没有标准的注册服务.

There is no way of programmatically discovering REST services as they do not have a standard registry service.

除了做一些疯狂的蛮力搜索之外,没有办法找到正确的 URL(更不用说正确的参数了).所以唯一的选择是记录你的 API.为此,我目前看到的最佳选择是:

Apart from doing something insane brute-force search there is no way of finding the right URLs ( not to mention the right parameters). So the only option is documenting your API. For that the best choice I have seen so far is:

这篇关于有没有办法发现 ReST API 的所有端点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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