# api-config-request **Repository Path**: lucy96/api-config-request ## Basic Information - **Project Name**: api-config-request - **Description**: 提供api与方法之间关系的配置,减少编写接口调用函数的代码量 - **Primary Language**: NodeJS - **License**: ISC - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-16 - **Last Updated**: 2021-07-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 介绍 提供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访问路径 ```