Api管家系列(一):初探
前段时间发现一个很好用的API管理工具--API管家,用了一段时间,已经感觉离不开了,抱着分享使我快乐的想法,因为刚开始用的时候随便写过一篇简介,不是很详细,所以现在就重新写,把我这段时间使用的经验和大家一起讨论。
进入正题:打开浏览器,输入www.apigj.com 来到首页,接下来自然是登录或注册了

创建一个新账号,成功后会来到项目列表界面,会提示是否需要创建示例项目,点击确定后,就会创建一个新的项目出来


点击进入示例项目,示例项目一共有1个文件夹和5个接口,可以看到没有经过测试,都在未测试状态

点击某个接口,接口文档就显示出来了,有请求的URL,版本号,描述,请求方式,参数等等,左上角是对接口的操作按扭

点击编辑,可以看到编辑接口的界面,注意我红色圈出的位置是个tab控件,可以点击切换编辑的内容

把请求Class的openid直接删除,点击保存

回到接口文档页面,可以看到openid已经从请求Class里消失了,这里还有个特别的功能,我用红色图出了,点击会生成mock参数


点击左上角的生成按扭,这里就是Api管家最大特色了,可以直接生成代码

点击生成代码,会出现语言的选项,一共9种语言,对我来说是足够用了

举个栗子,我常用的Java(咖啡杯),又分3种引入包

选择Gson

请求和返回的Class文件就直接生成了,值的提一下的是ResSendSms继承于ResCommon,这个是在文档中编辑的,下次再展开细说编辑的功能
上生成的代码,里面自动带了文档中的描述作为注释,实在是太方便了
/***
* @接口:SendSMS
* @URL:host + /sendsms
* @编码:www.apigj.com
* @版本号:1.1
***/ import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter; @JsonAdapter(ReqSendSms.ReqSendSmsTypeAdapter.class)
public class ReqSendSms {
// 类型版本,用于查询类型是否已过期
public static final int Version = 2; /***
* 参数描述:用户手机号
* 是否可为空:否
***/
@SerializedName("mobile")
private String mobile;
public String getMobile(){
return mobile;
}
public void setMobile(String mobile){
this.mobile = mobile;
} /***
* 检查类型完整性
*
* @return true代表类型通过完整性检查
***/
public boolean checkVarRequire() {
if(getMobile() == null){
System.out.println("Lake of (mobile)");
return false;
}
return true;
} public static class ReqSendSmsTypeAdapter<T> extends TypeAdapter<ReqSendSms> {
@Override
public void write(JsonWriter out, ReqSendSms value) throws IOException {
out.beginObject();
writeOBJ(out, (ReqSendSms)value);
out.endObject();
} protected void writeOBJ(JsonWriter out, ReqSendSms value) throws IOException {
out.name("mobile").value(value.getMobile());
} @Override
public ReqSendSms read(JsonReader in) throws IOException {
ReqSendSms res = new ReqSendSms();
in.beginObject();
while (in.hasNext()) {
String propertyName = in.nextName();
if(!readOBJ(res, in, propertyName)) {
in.skipValue();
}
}
in.endObject();
return res;
} protected boolean readOBJ(ReqSendSms res, JsonReader in, String propertyName) throws IOException {
if (propertyName.equals("mobile")) {
try {
res.setMobile(in.nextString());
} catch(IllegalStateException e) {in.skipValue();}
return true;
}
return false;
} } }
请求类 ReqSendSms.java
/***
* @接口:SendSMS
* @URL:host + /sendsms
* @编码:www.apigj.com
* @版本号:1.1
***/ import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter; @JsonAdapter(ResCommon.ResCommonTypeAdapter.class)
public class ResCommon {
// 类型版本,用于查询类型是否已过期
public static final int Version = 1; /***
* 参数描述:返回码
* 是否可为空:否
***/
@SerializedName("code")
private Integer code;
public Integer getCode(){
return code;
}
public void setCode(Integer code){
this.code = code;
} /***
* 参数描述:返回提示
* 是否可为空:是
***/
@SerializedName("msg")
private String msg;
public String getMsg(){
return msg;
}
public void setMsg(String msg){
this.msg = msg;
} /***
* 检查类型完整性
*
* @return true代表类型通过完整性检查
***/
public boolean checkVarRequire() {
if(getCode() == null){
System.out.println("Lake of (code)");
return false;
}
return true;
} public static class ResCommonTypeAdapter<T> extends TypeAdapter<ResCommon> {
@Override
public void write(JsonWriter out, ResCommon value) throws IOException {
out.beginObject();
writeOBJ(out, (ResCommon)value);
out.endObject();
} protected void writeOBJ(JsonWriter out, ResCommon value) throws IOException {
out.name("code").value(value.getCode());
out.name("msg").value(value.getMsg());
} @Override
public ResCommon read(JsonReader in) throws IOException {
ResCommon res = new ResCommon();
in.beginObject();
while (in.hasNext()) {
String propertyName = in.nextName();
if(!readOBJ(res, in, propertyName)) {
in.skipValue();
}
}
in.endObject();
return res;
} protected boolean readOBJ(ResCommon res, JsonReader in, String propertyName) throws IOException {
if (propertyName.equals("code")) {
try {
res.setCode(in.nextInt());
} catch(IllegalStateException e) {in.skipValue();}
return true;
}
else if (propertyName.equals("msg")) {
try {
res.setMsg(in.nextString());
} catch(IllegalStateException e) {in.skipValue();}
return true;
}
return false;
} } }
返回类的父类 ResCommon.java
/***
* @接口:SendSMS
* @URL:host + /sendsms
* @编码:www.apigj.com
* @版本号:1.1
***/ import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter; @JsonAdapter(ResSendSms.ResSendSmsTypeAdapter.class)
public class ResSendSms extends ResCommon {
// 类型版本,用于查询类型是否已过期
public static final int Version = 2; /***
* 参数描述:事件ID,记录接收短信的用户
* 是否可为空:否
***/
@SerializedName("eventid")
private String eventid;
public String getEventid(){
return eventid;
}
public void setEventid(String eventid){
this.eventid = eventid;
} /***
* 检查类型完整性
*
* @return true代表类型通过完整性检查
***/
public boolean checkVarRequire() {
if(!super.checkVarRequire()){
return false;
}
if(getEventid() == null){
System.out.println("Lake of (eventid)");
return false;
}
return true;
} public static class ResSendSmsTypeAdapter<T> extends ResCommonTypeAdapter<ResSendSms> {
@Override
public void write(JsonWriter out, ResCommon value) throws IOException {
out.beginObject();
writeOBJ(out, (ResSendSms)value);
out.endObject();
} protected void writeOBJ(JsonWriter out, ResSendSms value) throws IOException {
super.writeOBJ(out, value);
out.name("eventid").value(value.getEventid());
} @Override
public ResSendSms read(JsonReader in) throws IOException {
ResSendSms res = new ResSendSms();
in.beginObject();
while (in.hasNext()) {
String propertyName = in.nextName();
if(!readOBJ(res, in, propertyName)) {
in.skipValue();
}
}
in.endObject();
return res;
} protected boolean readOBJ(ResSendSms res, JsonReader in, String propertyName) throws IOException {
if (super.readOBJ(res, in, propertyName)) {
return true;
}else
if (propertyName.equals("eventid")) {
try {
res.setEventid(in.nextString());
} catch(IllegalStateException e) {in.skipValue();}
return true;
}
return false;
} } }
返回类 ResSendSms.java
具体请求返回代码还是要自己写的,希望API管家继续完善,以后也可以自动生成把URL和请求方法,请求头包括进去,那就更完美了(懒癌又发作了)。。。
Api管家系列(一):初探的更多相关文章
- Api管家系列(三):测试和Rest Client
今天我们来看一下Api管家的测试功能 在项目首页可以看到,测试过的接口和未测试的接口,点击环型图能列出相应的接口 我们选择未测试的,这些接口我都已经实现好了,只是没有用API管家进行测试,所以还显示未 ...
- Api管家系列(二):编辑和继承Class
上篇写了个大概,今天我详细说一下参数的编辑,废话不多说 先打开一个项目,我要特别说一下设置里的“默认参数设置” 打开默认参数设置,这里我用红色圈出的tab可以设置请求头,返回头和返回状态,这些设置会在 ...
- openlayers5-webpack 入门开发系列一初探篇(附源码下载)
前言 openlayers5-webpack 入门开发系列环境知识点了解: node 安装包下载webpack 打包管理工具需要依赖 node 环境,所以 node 安装包必须安装,上面链接是官网下载 ...
- leaflet-webpack 入门开发系列一初探篇(附源码下载)
前言 leaflet-webpack 入门开发系列环境知识点了解: node 安装包下载webpack 打包管理工具需要依赖 node 环境,所以 node 安装包必须安装,上面链接是官网下载地址 w ...
- Hadoop MapReduce编程 API入门系列之压缩和计数器(三十)
不多说,直接上代码. Hadoop MapReduce编程 API入门系列之小文件合并(二十九) 生成的结果,作为输入源. 代码 package zhouls.bigdata.myMapReduce. ...
- 淘宝API开发系列---阿里.聚石塔.开放平台的使用
好久没有继续跟进淘宝的API使用了,有很多做相关应用的同行都来咨询,很多都因为自己开发工作比较忙而没有来得及好的处理,前几天,有一个朋友叫帮忙指导如何使用淘宝API,由于原来有一些成熟的例子应用,因此 ...
- ASP.NET Web API实践系列04,通过Route等特性设置路由
ASP.NET Web API路由,简单来说,就是把客户端请求映射到对应的Action上的过程.在"ASP.NET Web API实践系列03,路由模版, 路由惯例, 路由设置"一 ...
- 构建安全的Xml Web Service系列之初探使用Soap头
原文:构建安全的Xml Web Service系列之初探使用Soap头 Xml Web Service 从诞生那天就说自己都么都么好,还津津乐道的说internet也会因此而进入一个新纪元,可5年多来 ...
- 循序渐进学.Net Core Web Api开发系列【0】:序言与目录
一.序言 我大约在2003年时候开始接触到.NET,最初在.NET framework 1.1版本下写过代码,曾经做过WinForm和ASP.NET开发.大约在2010年的时候转型JAVA环境,这么多 ...
随机推荐
- 在Visual Studio中使用Debug Visualizers在C++中实现对原始类的自定义调试信息显示
在Visual Studio中使用Debug Visualizers在C++中实现对原始类的自定义调试信息显示 当我们在VS的C++中使用vector.list.map等这些STL容器,在开启调试的时 ...
- 对于 Netty ByteBuf 的零拷贝(Zero Copy) 的理解
此文章已同步发布在我的 segmentfault 专栏. 根据 Wiki 对 Zero-copy 的定义: "Zero-copy" describes computer opera ...
- 第四章——训练模型(Training Models)
前几章在不知道原理的情况下,已经学会使用了多个机器学习模型机器算法.Scikit-Learn很方便,以至于隐藏了太多的实现细节. 知其然知其所以然是必要的,这有利于快速选择合适的模型.正确的训练算法. ...
- bootstrap table的样式
<style> table{ border: 1px solid #ddd; background-color: transparent; border-spacing:; border- ...
- 究竟谁在绑架中国的4G政策?
2009年中国正式发放3G牌照以来,尽管在开始阶段受到了应用不足的困扰,但是随着智 能手机的迅速推广,3G移动通信也开始在中国得到了飞速的发展.就在消费者以及市场 逐步接受并广泛应用该技术之际,4G通 ...
- CentOS6.5 安装Python2.7后, yum出现“No module named yum”错误
安装如下方法安装python2.7: yum install –y python27 python27-devel python-docutils cd /usr/bin/ rm -rf python ...
- Asp.Net Core NLog 将日志输出到数据库以及添加LayoutRenderer的支持
在这之前打算用Apache的Log4Net,但是发现其AdoNetAppender方法已经不存在了,无法使用配置文件直接输出到数据库了,因此我便改用了NLog框架. 一.对项目添加NLog 通过Nug ...
- intelij IDEA破解
破解intelij IDEA请见链接:https://blog.csdn.net/weixin_37937646/article/details/79119540
- admin-handlers.go
package],,) ],,) ],,) ],,) ],,) ]) if err == redis.Nil { http.NotFound(w, r) } else ...
- ANSI 和 UNICODE 的函数对应表
ANSI UNICODE 通用(char.h) (wchar.h) (tchar.h) char wchar_t ...