前段时间发现一个很好用的API管理工具--API管家,用了一段时间,已经感觉离不开了,抱着分享使我快乐的想法,因为刚开始用的时候随便写过一篇简介,不是很详细,所以现在就重新写,把我这段时间使用的经验和大家一起讨论。

进入正题:打开浏览器,输入www.apigj.com 来到首页,接下来自然是登录或注册了

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

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

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

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

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

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

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

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

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

选择Gson

请求和返回的Class文件就直接生成了,值的提一下的是ResSendSms继承于ResCommon,这个是在文档中编辑的,下次再展开细说编辑的功能

上生成的代码,里面自动带了文档中的描述作为注释,实在是太方便了

  1. /***
  2. * @接口:SendSMS
  3. * @URL:host + /sendsms
  4. * @编码:www.apigj.com
  5. * @版本号:1.1
  6. ***/
  7.  
  8. import java.io.IOException;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. import com.google.gson.TypeAdapter;
  13. import com.google.gson.annotations.JsonAdapter;
  14. import com.google.gson.annotations.SerializedName;
  15. import com.google.gson.stream.JsonReader;
  16. import com.google.gson.stream.JsonWriter;
  17.  
  18. @JsonAdapter(ReqSendSms.ReqSendSmsTypeAdapter.class)
  19. public class ReqSendSms {
  20. // 类型版本,用于查询类型是否已过期
  21. public static final int Version = 2;
  22.  
  23. /***
  24. * 参数描述:用户手机号
  25. * 是否可为空:否
  26. ***/
  27. @SerializedName("mobile")
  28. private String mobile;
  29. public String getMobile(){
  30. return mobile;
  31. }
  32. public void setMobile(String mobile){
  33. this.mobile = mobile;
  34. }
  35.  
  36. /***
  37. * 检查类型完整性
  38. *
  39. * @return true代表类型通过完整性检查
  40. ***/
  41. public boolean checkVarRequire() {
  42. if(getMobile() == null){
  43. System.out.println("Lake of (mobile)");
  44. return false;
  45. }
  46. return true;
  47. }
  48.  
  49. public static class ReqSendSmsTypeAdapter<T> extends TypeAdapter<ReqSendSms> {
  50. @Override
  51. public void write(JsonWriter out, ReqSendSms value) throws IOException {
  52. out.beginObject();
  53. writeOBJ(out, (ReqSendSms)value);
  54. out.endObject();
  55. }
  56.  
  57. protected void writeOBJ(JsonWriter out, ReqSendSms value) throws IOException {
  58. out.name("mobile").value(value.getMobile());
  59. }
  60.  
  61. @Override
  62. public ReqSendSms read(JsonReader in) throws IOException {
  63. ReqSendSms res = new ReqSendSms();
  64. in.beginObject();
  65. while (in.hasNext()) {
  66. String propertyName = in.nextName();
  67. if(!readOBJ(res, in, propertyName)) {
  68. in.skipValue();
  69. }
  70. }
  71. in.endObject();
  72. return res;
  73. }
  74.  
  75. protected boolean readOBJ(ReqSendSms res, JsonReader in, String propertyName) throws IOException {
  76. if (propertyName.equals("mobile")) {
  77. try {
  78. res.setMobile(in.nextString());
  79. } catch(IllegalStateException e) {in.skipValue();}
  80. return true;
  81. }
  82. return false;
  83. }
  84.  
  85. }
  86.  
  87. }

请求类 ReqSendSms.java

  1. /***
  2. * @接口:SendSMS
  3. * @URL:host + /sendsms
  4. * @编码:www.apigj.com
  5. * @版本号:1.1
  6. ***/
  7.  
  8. import java.io.IOException;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. import com.google.gson.TypeAdapter;
  13. import com.google.gson.annotations.JsonAdapter;
  14. import com.google.gson.annotations.SerializedName;
  15. import com.google.gson.stream.JsonReader;
  16. import com.google.gson.stream.JsonWriter;
  17.  
  18. @JsonAdapter(ResCommon.ResCommonTypeAdapter.class)
  19. public class ResCommon {
  20. // 类型版本,用于查询类型是否已过期
  21. public static final int Version = 1;
  22.  
  23. /***
  24. * 参数描述:返回码
  25. * 是否可为空:否
  26. ***/
  27. @SerializedName("code")
  28. private Integer code;
  29. public Integer getCode(){
  30. return code;
  31. }
  32. public void setCode(Integer code){
  33. this.code = code;
  34. }
  35.  
  36. /***
  37. * 参数描述:返回提示
  38. * 是否可为空:是
  39. ***/
  40. @SerializedName("msg")
  41. private String msg;
  42. public String getMsg(){
  43. return msg;
  44. }
  45. public void setMsg(String msg){
  46. this.msg = msg;
  47. }
  48.  
  49. /***
  50. * 检查类型完整性
  51. *
  52. * @return true代表类型通过完整性检查
  53. ***/
  54. public boolean checkVarRequire() {
  55. if(getCode() == null){
  56. System.out.println("Lake of (code)");
  57. return false;
  58. }
  59. return true;
  60. }
  61.  
  62. public static class ResCommonTypeAdapter<T> extends TypeAdapter<ResCommon> {
  63. @Override
  64. public void write(JsonWriter out, ResCommon value) throws IOException {
  65. out.beginObject();
  66. writeOBJ(out, (ResCommon)value);
  67. out.endObject();
  68. }
  69.  
  70. protected void writeOBJ(JsonWriter out, ResCommon value) throws IOException {
  71. out.name("code").value(value.getCode());
  72. out.name("msg").value(value.getMsg());
  73. }
  74.  
  75. @Override
  76. public ResCommon read(JsonReader in) throws IOException {
  77. ResCommon res = new ResCommon();
  78. in.beginObject();
  79. while (in.hasNext()) {
  80. String propertyName = in.nextName();
  81. if(!readOBJ(res, in, propertyName)) {
  82. in.skipValue();
  83. }
  84. }
  85. in.endObject();
  86. return res;
  87. }
  88.  
  89. protected boolean readOBJ(ResCommon res, JsonReader in, String propertyName) throws IOException {
  90. if (propertyName.equals("code")) {
  91. try {
  92. res.setCode(in.nextInt());
  93. } catch(IllegalStateException e) {in.skipValue();}
  94. return true;
  95. }
  96. else if (propertyName.equals("msg")) {
  97. try {
  98. res.setMsg(in.nextString());
  99. } catch(IllegalStateException e) {in.skipValue();}
  100. return true;
  101. }
  102. return false;
  103. }
  104.  
  105. }
  106.  
  107. }

返回类的父类 ResCommon.java

  1. /***
  2. * @接口:SendSMS
  3. * @URL:host + /sendsms
  4. * @编码:www.apigj.com
  5. * @版本号:1.1
  6. ***/
  7.  
  8. import java.io.IOException;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. import com.google.gson.TypeAdapter;
  13. import com.google.gson.annotations.JsonAdapter;
  14. import com.google.gson.annotations.SerializedName;
  15. import com.google.gson.stream.JsonReader;
  16. import com.google.gson.stream.JsonWriter;
  17.  
  18. @JsonAdapter(ResSendSms.ResSendSmsTypeAdapter.class)
  19. public class ResSendSms extends ResCommon {
  20. // 类型版本,用于查询类型是否已过期
  21. public static final int Version = 2;
  22.  
  23. /***
  24. * 参数描述:事件ID,记录接收短信的用户
  25. * 是否可为空:否
  26. ***/
  27. @SerializedName("eventid")
  28. private String eventid;
  29. public String getEventid(){
  30. return eventid;
  31. }
  32. public void setEventid(String eventid){
  33. this.eventid = eventid;
  34. }
  35.  
  36. /***
  37. * 检查类型完整性
  38. *
  39. * @return true代表类型通过完整性检查
  40. ***/
  41. public boolean checkVarRequire() {
  42. if(!super.checkVarRequire()){
  43. return false;
  44. }
  45. if(getEventid() == null){
  46. System.out.println("Lake of (eventid)");
  47. return false;
  48. }
  49. return true;
  50. }
  51.  
  52. public static class ResSendSmsTypeAdapter<T> extends ResCommonTypeAdapter<ResSendSms> {
  53. @Override
  54. public void write(JsonWriter out, ResCommon value) throws IOException {
  55. out.beginObject();
  56. writeOBJ(out, (ResSendSms)value);
  57. out.endObject();
  58. }
  59.  
  60. protected void writeOBJ(JsonWriter out, ResSendSms value) throws IOException {
  61. super.writeOBJ(out, value);
  62. out.name("eventid").value(value.getEventid());
  63. }
  64.  
  65. @Override
  66. public ResSendSms read(JsonReader in) throws IOException {
  67. ResSendSms res = new ResSendSms();
  68. in.beginObject();
  69. while (in.hasNext()) {
  70. String propertyName = in.nextName();
  71. if(!readOBJ(res, in, propertyName)) {
  72. in.skipValue();
  73. }
  74. }
  75. in.endObject();
  76. return res;
  77. }
  78.  
  79. protected boolean readOBJ(ResSendSms res, JsonReader in, String propertyName) throws IOException {
  80. if (super.readOBJ(res, in, propertyName)) {
  81. return true;
  82. }else
  83. if (propertyName.equals("eventid")) {
  84. try {
  85. res.setEventid(in.nextString());
  86. } catch(IllegalStateException e) {in.skipValue();}
  87. return true;
  88. }
  89. return false;
  90. }
  91.  
  92. }
  93.  
  94. }

返回类 ResSendSms.java

具体请求返回代码还是要自己写的,希望API管家继续完善,以后也可以自动生成把URL和请求方法,请求头包括进去,那就更完美了(懒癌又发作了)。。。

Api管家系列(一):初探的更多相关文章

  1. Api管家系列(三):测试和Rest Client

    今天我们来看一下Api管家的测试功能 在项目首页可以看到,测试过的接口和未测试的接口,点击环型图能列出相应的接口 我们选择未测试的,这些接口我都已经实现好了,只是没有用API管家进行测试,所以还显示未 ...

  2. Api管家系列(二):编辑和继承Class

    上篇写了个大概,今天我详细说一下参数的编辑,废话不多说 先打开一个项目,我要特别说一下设置里的“默认参数设置” 打开默认参数设置,这里我用红色圈出的tab可以设置请求头,返回头和返回状态,这些设置会在 ...

  3. openlayers5-webpack 入门开发系列一初探篇(附源码下载)

    前言 openlayers5-webpack 入门开发系列环境知识点了解: node 安装包下载webpack 打包管理工具需要依赖 node 环境,所以 node 安装包必须安装,上面链接是官网下载 ...

  4. leaflet-webpack 入门开发系列一初探篇(附源码下载)

    前言 leaflet-webpack 入门开发系列环境知识点了解: node 安装包下载webpack 打包管理工具需要依赖 node 环境,所以 node 安装包必须安装,上面链接是官网下载地址 w ...

  5. Hadoop MapReduce编程 API入门系列之压缩和计数器(三十)

    不多说,直接上代码. Hadoop MapReduce编程 API入门系列之小文件合并(二十九) 生成的结果,作为输入源. 代码 package zhouls.bigdata.myMapReduce. ...

  6. 淘宝API开发系列---阿里.聚石塔.开放平台的使用

    好久没有继续跟进淘宝的API使用了,有很多做相关应用的同行都来咨询,很多都因为自己开发工作比较忙而没有来得及好的处理,前几天,有一个朋友叫帮忙指导如何使用淘宝API,由于原来有一些成熟的例子应用,因此 ...

  7. ASP.NET Web API实践系列04,通过Route等特性设置路由

    ASP.NET Web API路由,简单来说,就是把客户端请求映射到对应的Action上的过程.在"ASP.NET Web API实践系列03,路由模版, 路由惯例, 路由设置"一 ...

  8. 构建安全的Xml Web Service系列之初探使用Soap头

    原文:构建安全的Xml Web Service系列之初探使用Soap头 Xml Web Service 从诞生那天就说自己都么都么好,还津津乐道的说internet也会因此而进入一个新纪元,可5年多来 ...

  9. 循序渐进学.Net Core Web Api开发系列【0】:序言与目录

    一.序言 我大约在2003年时候开始接触到.NET,最初在.NET framework 1.1版本下写过代码,曾经做过WinForm和ASP.NET开发.大约在2010年的时候转型JAVA环境,这么多 ...

随机推荐

  1. 【机器学习】使用gensim 的 doc2vec 实现文本相似度检测

    环境 Python3, gensim,jieba,numpy ,pandas 原理:文章转成向量,然后在计算两个向量的余弦值. Gensim gensim是一个python的自然语言处理库,能够将文档 ...

  2. nginx常用配置系列-虚拟主机

    本来准备详尽的出一份nginx配置讲解,但nginx功能配置繁多,平常使用中使用最多的一般有: 1. 虚拟主机配置 2. HTTPS配置 3. 静态资源处理 4. 反向代理 ============= ...

  3. 云计算大数据:Xen、KVM、VMware、hyper-v等虚拟化技术的比较

    1.Xen.KVM.VMware.hyper-v等虚拟化技术的比较,xen和kvm,是开源免费的虚拟化软件. vmware是付费的虚拟化软件. hyper-v比较特别,是微软windows 2008 ...

  4. 调用约定__cdecl __fastcall与__stdcall

    __cdecl __fastcall与__stdcall,三者都是调用约定(Calling convention),它决定以下内容:1)函数参数的压栈顺序,2)由调用者还是被调用者把参数弹出栈,3)以 ...

  5. 基于Mybatis的Dao层的开发

    基于Mybatis的Dao层开发 SqlSessionFactoryBuilder用于创建SqlSessionFacoty,SqlSessionFacoty一旦创建完成就不需要SqlSessionFa ...

  6. PAT1102: Invert a Binary Tree

    1102. Invert a Binary Tree (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  7. Linux共享库、静态库、动态库详解

    1. 介绍 使用GNU的工具我们如何在Linux下创建自己的程序函数库?一个“程序函数库”简单的说就是一个文件包含了一些编译好的代码和数据,这些编译好的代码和数据可以在事后供其他的程序使用.程序函数库 ...

  8. Spring cloud整体框架

    研究了一段时间spring boot了准备向spirng cloud进发,公司架构和项目也全面拥抱了Spring Cloud.在使用了一段时间后发现Spring Cloud从技术架构上降低了对大型系统 ...

  9. vue学习之响应式原理的demo实现

    Vue.js 核心: 1.响应式的数据绑定系统 2.组件系统. 访问器属性 访问器属性是对象中的一种特殊属性,它不能直接在对象中设置,而必须通过 defineProperty() 方法单独定义. va ...

  10. handler.go

    {         w.WriteHeader(http.StatusAccepted)     } else {         errStr := ""         for ...