最近在做一个API接口开放平台,目前做到了api发布与测试阶段,同样也有供给用户使用的sdk
在接口发布的代码中,我们的业务逻辑是首先判断api在db中是否存在,其次我们再判断api的可用性。
在客户端的sdk中,我们一定也是需要对api进行通讯测试,所以我们干脆在服务端中引入客户端的jar不就行了。
首先,API的Method有多个,我们可以通过枚举类来实现

传入的Body也类似,常见的有Json和Param类型,同理

下面是检测函数,这里我们使用了Hutool框架,然后我们通过反射来获取请求类型名

sdk-starter创建
我们可以通过将sdk封装为一个starter然后再通过Maven导入到服务端
删除test,然后在resources中创建META-INF目录,再创建spring.factories文件,用于将类注入到外部项目的容器中,下面的代码表示自动加载配置类的配置。

然后直接install即可

在pom中,注意这一项

直接复制到其他项目的pom.xml中即可
(对于Client的配置我们也可以在服务端的yml中完成)

正文完