1.0.1 • Published 8 years ago

labset-client-js v1.0.1

Weekly downloads
-
License
Apache-2.0
Repository
bitbucket
Last release
8 years ago

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 : '' });
...
1.0.1

8 years ago

1.0.0

8 years ago

0.1.0

8 years ago

0.0.1

8 years ago