https://github.com/unicreators/extend-api
extend api.
https://github.com/unicreators/extend-api
api extend web-api
Last synced: about 1 month ago
JSON representation
extend api.
- Host: GitHub
- URL: https://github.com/unicreators/extend-api
- Owner: unicreators
- License: mit
- Created: 2017-09-12T08:05:57.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-13T03:29:18.000Z (almost 9 years ago)
- Last Synced: 2025-01-28T16:47:18.291Z (over 1 year ago)
- Topics: api, extend, web-api
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## extend-api
extend api.
## Install
```sh
$ npm install extend-api
```
## Usage
### Custom api
```js
const { Api, ApiExtend } = require('extend-api');
let CustomApi = class customApi extends Api {
constructor(token) { super(); this.token = token; }
// override
async buildApiReqOpts(extendInvokeOpts) {
// attach 'token'
extendInvokeOpts.qs = Object.assign({ token: this.token }, extendInvokeOpts.qs);
return extendInvokeOpts;
}
};
```
### Custom extend
```js
let MessageExtend = class MessageExtend extends ApiExtend {
async send(to, content) {
return await this.invoke(
'https://api.weixin.qq.com/cgi-bin/message/custom/send',
// request opts.
// (see: https://github.com/request/request#requestoptions-callback)
{
body: {
touser: to, msgtype: 'text',
text: { content }
}
}, 'POST');
}
};
```
### Register extend
```js
let api = new CustomApi('token..');
// register
api.extend('message', MessageExtend);
```
### Use
```js
api.message.send('to', 'content')
.then(function (result) {
// ..
}).catch(function (err) {
// ..
});
// or
// await api.message.send('openId', 'content');
```
### License
[MIT](LICENSE)