4.0.0 • Published 6 years ago

apinterface v4.0.0

Weekly downloads
64
License
GPL-3.0
Repository
github
Last release
6 years ago

APInterface

Dependencies NPM Downloads License

APInterface aims to provide a fluid interface to a collection of different APIs.

Supported Services

Is there a service you'd like to see added? Let me know.

Installation

npm i --save apinterface

Usage

import { Twitch } from 'apinterface';

Twitch.setConfig({
    client_id: '',
    access_token: '',
});

Twitch.getFollowers('oyed', {
    limit: 20,
}).then(data => {
    //
});

Automatically Refresh Tokens

For services that don't supply long-lived Tokens, you need to refresh them every once in a while. APInterface will allow you to do this automatically when it detects an invalid/expired Token, but requires a bit of setup.

Web Applications

As refreshing an Access Token requires your Application Secret Key, which should never be publicly visible, APInterface will require a URL to send a request to in order to refresh the Access Token. Here are a few Guides on implementing refreshing Tokens:

You can then specify a refresh.url when setting the config for a given Interface, for example:

YouTube.refresh.url = '/my/refresh/url';

APInterface will send a request to this URL and expects a JSON response with keys matching the given Interfaces config keys. For example, the YouTube Interface requires an access_token to be given through YouTube.setConfig, so when a request is made to the Refresh URL, it'll expect the response JSON to contain an access_token field containing the newly refreshed Access Token.

Any information in the JSON response will be run through Api.setConfig for the given Interface. You can also pass data to the Refresh URL by passing through the refresh.data config parameter:

YouTube.refresh = {
    url: '/my/refresh/url',
    data: {
        hello: 'world',
    },
};

This data will be passed to the Refresh URL as GET parameters.

Node Applications

As Node is server-side, you don't have to send a request to your server, getting rid of some overhead and generally making the process a little easier. Instead of passing through a refresh.url, you can instead pass a refresh.callback, which will be called when a Token Refresh is needed.

APInterface expects this function to return a Promise. For example:

YouTube.refresh.callback = () => new Promise((resolve, reject) => {
    // Attempt to refresh the Token in here.
    // If successful, make the following call.
    resolve(data);

    // Otherwise, make the following call.
    reject();
});

The data parameter passed to the resolve method in the Promise will, like with the Web App process, be ran through YouTube.setConfig to set the new config values for the Interface. For example, with the YouTube Interface, you'd have to provide an object with an access_token property so that it can overwrite the now expired Token.

TODO

  • Finish initial Interfaces
  • Add and maintain Documentation
  • Add Transformers to unify return structures
4.0.0

6 years ago

3.4.0

7 years ago

3.3.0

7 years ago

3.2.0

7 years ago

3.1.9

7 years ago

3.1.8

7 years ago

3.1.7

7 years ago

3.1.6

7 years ago

3.1.5

7 years ago

3.1.4

7 years ago

3.1.3

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.0

8 years ago

1.1.7

8 years ago

1.1.6

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.22

8 years ago

1.0.21

8 years ago

1.0.20

8 years ago

1.0.19

8 years ago

1.0.18

8 years ago

1.0.17

8 years ago

1.0.16

8 years ago

1.0.15

8 years ago

1.0.14

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.1.0

8 years ago