# extend-api

> extend api.

Latest version **1.0.2** (published 2017-09-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install extend-api
pnpm add extend-api
yarn add extend-api
bun add extend-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2017-09-13 |
| First published | 2017-09-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | yichen |
| Maintainers | unicreators |
| Keywords | web api, extend, api |

## Links

- npm: https://www.npmjs.com/package/extend-api
- Repository: https://github.com/unicreators/extend-api
- Homepage: https://github.com/unicreators/extend-api#readme
- Issues: https://github.com/unicreators/extend-api/issues
- npm.io page: https://npm.io/package/extend-api

## Dependencies (2)

- [request](https://npm.io/package/request.md) ^2.81.0
- [request-promise-native](https://npm.io/package/request-promise-native.md) ^1.0.4

## Recent versions

- 1.0.2 (latest) — 2017-09-13
- 1.0.1 — 2017-09-12
- 1.0.0 — 2017-09-12

## 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)

---
_Source: https://npm.io/package/extend-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
