0.0.3 • Published 7 years ago

rest-room v0.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

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);
	});
});
0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago