0.0.2 • Published 7 years ago
@nichoth/http-helper v0.0.2
http helper
Special helper for http calls
install
$ npm install @nichoth/http-helper
example
var HttpRequest = require('../')
var assert = require('assert')
// return data that you can pass to xhr/request
var RequestData = HttpRequest({
url: 'http://localhost:8000',
method: 'POST',
headers: { foo: 'bar' },
body: { a: 'b' },
json: true
})
// add more stuff to the request body
var data = RequestData({ test: 'test' })
console.log(data)
assert.deepEqual(data, {
url: 'http://localhost:8000',
method: 'POST',
headers: { foo: 'bar' },
body: { a: 'b', test: 'test' },
json: true
})
// add some stuff to the url path
var FooRequest = RequestData(['foo'])
// add some stuff to the request body
var fooData = FooRequest({ hello: 'world' })
console.log(fooData)
assert.deepEqual(fooData, {
url: 'http://localhost:8000/foo',
method: 'POST',
headers: { foo: 'bar' },
body: { a: 'b', hello: 'world' },
json: true
})
// get the data, don't add any more stuff
var _data = FooRequest()
console.log('_data', _data)
assert.deepEqual(_data, {
url: 'http://localhost:8000/foo',
method: 'POST',
headers: { foo: 'bar' },
body: { a: 'b' },
json: true
})