rest-room
v0.0.3
Published
Node-based rest client utilizing Promises with a brain dead simple api. Originally created to be used in conjuction with mocha, chai and chai-as-promised.
Downloads
3
Readme
rest-room
A Node-based rest client utilizing Promises with a brain dead simple api. This modules was originally created to work in conjuction with mocha, chai and chai-as-promised.
Installation
npm install rest-room --save
Simple GET request
import {get} from 'rest-room';
get('http://google.com').then(data => {
console.log(data);
});
Providing Headers
let headers = {
'Some-Header': 'foo'
};
get('http://google.com', headers).then(data => {
console.log(data);
});
Simple POST request
import {post} from 'rest-room';
let body = {
some: 'body'
};
post('http://some-json-endpoint/', body).then(data => {
console.log(data);
});
POST with headers
import {post} from 'rest-room';
let body = {
some: 'body'
};
let headers = {
'Some-Header': 'foo'
};
post('http://some-json-endpoint/', body, headers).then(data => {
console.log(data);
});
Using with mocha chai and chai-as-promised
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import {post} from 'rest-room';
chai.use(chaiAsPromised);
describe('Some endpoint', () => {
it('response should match expected', (done) => {
let body = {foo: 'bar'};
let expected = '{"some": "response"}';
post('http://some-endpoint/', body).to.eventually.equal(expected).notify(done);
});
});