labset-client-js
v1.0.1
Published
labset client js
Downloads
5
Readme
labset-client-js
a "promise"ing rest client
install it
npm install labset-client-js --save
use it
// use default client
import { Client } from 'labset-client-js';
const basicAuth = { user : '', pass : '' };
const bearerAuth = { bearer : 'sometoken' };
const client = new Client({
endpoint : 'https://some.api.com/',
auth : basicAuth || bearerAuth
});
const data = yield client.get({ path : 'some/path', time : true });
const body = data.response.body;
const elapsedTime = data.response.elapsedTime;
// use client factory with custom client
import { ClientFactory, Client } from 'labset-client-js';
class CustomClient extends Client {
constructor(config) {
super(config);
}
resource(options) {
const headers = Object.assign({}, options.headers || {}, { 'my-custom-header' : ''});
options.headers = headers;
return super.resource(options);
}
}
const factory = new ClientFactory({
endpoint : ''
}, CustomClient);
const authOptions = {}
const client = yield factory.make(authOptions);
client.get({ path : '' });
...