nimbu-client
v3.1.1
Published
A thin wrapper for the Nimbu API
Downloads
79
Readme
nimbu-client
A thin wrapper around the Nimbu API.
Install
$ npm install nimbu-client --save
Usage
To begin, require the Nimbu module and create the client, passing in an API token:
const Nimbu = require('nimbu-client').default;
const nimbu = new Nimbu({ token: apiToken });
Or in Typescript:
import Nimbu from 'nimbu-client';
const nimbu = new Nimbu({ token: apiToken });
If a customer session token is needed, you can pass this too:
const nimbu = new Nimbu({ token: apiToken, sessionToken: sessionToken });
nimbu-client has get
, post
, patch
, and delete
functions which can make
requests with the specified HTTP method to any endpoint:
// GET requests
nimbu.get('/channels').then(channels => {
// do something with channel info
});
// POST requests with body
nimbu.post('/channels', { body: { name: 'foo' } }).then(channel => {});
// PATCH requests with body
nimbu.patch('/channels/foo', { body: { name: 'bar' } }).then(channel => {});
// DELETE requests
nimbu.delete('/channels/bar').then(channel => {});
There is also an even more generic request
function that can accept many more
options:
nimbu
.request({
method: 'GET',
path: '/channels',
parseJSON: false,
})
.then(response => {});
HTTP Proxies
If you'd like to make requests through an HTTP proxy, set the
NIMBU_HTTP_PROXY_HOST
environment variable with your proxy host, and
NIMBU_HTTP_PROXY_PORT
with the desired port (defaults to 8080). nimbu-client
will then make requests through this proxy instead of directly to
api.nimbu.io.
Running tests
nimbu-client uses ava for tests:
$ npm test