0.1.21 • Published 3 years ago

api-config-request v0.1.21

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

介绍

提供api与方法之间关系的配置,减少编写接口调用函数的代码量

使用方法

1.安装

npm install api-config-request

2.创建 api-config.js

import axios from "axios";
import ApiConfigRequest from 'api-config-request';

const config = {
  "multiServer":true,
  "defaultPath":"http://127.0.0.1:8080/",
  "apis":{
    "test":{
      "getPhotosContent":"GET a/{name1}/{name2}"
      "getOne":"GET a?{name1}&{name2}",
      "postOne":"POST a?{name1}"
    }
  }
}

const apis = ApiConfigRequest.getInstance().setRequests(axios).setApiConfig(config)
export default apis

3.在任意代码文件中引入 api-config.js

import apis from "api-config.js";

const testApi = apis.getModuleApis('test')

// 调用接口
testApi.getPhotosContent({
  width:"200",
  height:"200"
}).then(res=>{
  console.log(res.data);
})
配置项

multiServer: 是否开启多服务模式
defaultPath: 默认访问路径
servers:  多服务路径设置
  "moudle_name": 模块名,对应于api中的模块名
      path: 当前模块需要使用的服务路径,会与apis中的api访问路径做拼接

apis:  api调用关系配置
  "moudle_name": 模块名
      "PromiseFunction" : "method apiPath"   PromiseFunction:为该api调用时的方法名   method:请求方法 apiPath:api访问路径
0.1.21

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago