Skip to content

Nicolaschinc/InterfaceProxy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

InterfaceProxy

 Need nodejs >= 7.6.0

How to use

1.Define the requested server address and the interface-related configuration in the json file or js.

2.Instantiate the ProxyModel class and then call it.

const path = require('path');
const InterfaceProxy = require('interfaceproxy');

let pm = new InterfaceProxy(path.resolve(__dirname, './interface.json'));

let pm = new InterfaceProxy(path.resolve(__dirname, './interface.js'));

API

ProxyModel.getHttpOption(interfaceId)

Obtain the corresponding http request option in interface.json based on the interface id
let opt = pm.getHttpOption('getZhiHuData')

//{
//  hostname: 'news-at.zhihu.com',
//  port: 80,
//  path: '/api/4/news/latest',
//  method: 'GET',
//  headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' } 
//}

ProxyModel.send(option[,param])

According to the option to initiate a single interface request
  • option:[String | Object] Interface id or complete http request parameters (httpOption)
  • param: [Object] Relevant parameters required for the request interface
  • headers: [Object] Other headers

ProxyModel.url(id, path)

Reconcatenate the httpOption path parameter according to the interface id and path and then request
  • id: [String] Interface id
  • path: [String] Need to splicing address
  • param: [Object] Relevant parameters required by the request interface
  • headers: [Object] Other headers

ProxyModel.all(oprionArr)

Multi-interface data is obtained concurrently according to the configuration array
  • oprionArr: [Array] Interface configuration array

Interface configuration data format reference files interface.json and interface.js

About

NodeJS Interface Configuration Forwarding Tool.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%