0.0.7 • Published 10 years ago

chain-request v0.0.7

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

chain-request

A simple chainable, readable object with the intense to make speaking HTTP sane.

Installation

> npm install --save chain-request

Usage

Just include the module and name it, e.g.:

var request = require('chain-request');

Examples

Use the google REST-API

new request()
	.get('http://ajax.googleapis.com/ajax/services/search/web')
	.expects(request.CONTENT_TYPE.JSON)
	.data({
		v: '1.0',
		q: 'test'
	})
	.send(function(data) {
		data.responseData.results.forEach(function(result) {
			console.log(result);
		});
	});

Upload a file with authorization Header

new request()
	.post('https://build.phonegap.com/api/v1/apps')
	.expects(request.CONTENT_TYPE.JSON)
	.addAuthorizationHeader('Basic: a2Vrc2U6a3VjaGVu')
	.data('app.zip')
	.sendMultipart()
	.send(function(result) {
		console.log(result);
	})

Get a specific jira task

new request()
	.get('https://my-jira.tld/rest/api/2/issue/FOO-39')
	.expects(request.CONTENT_TYPE.JSON)
	.addAuthorizationHeader('Basic: a2Vrc2U6a3VjaGVu')
	.send(function(result) {
		console.log(result);
	})

API

Functions

Kind: global function

ParamTypeDefaultDescription
debugbooleanfalseenable debugging with true

get() ⇒ object

make a get request

Kind: global function
Returns: object - self

put() ⇒ object

make a put request

Kind: global function
Returns: object - self

post() ⇒ object

make a post request

Kind: global function
Returns: object - self

patch() ⇒ object

make a patch request

delete() ⇒ object

make a delete request

Kind: global function
Returns: object - self

options() ⇒ object

make a options request

Kind: global function
Returns: object - self

head() ⇒ object

make a head request

Kind: global function
Returns: object - self

Kind: global function
Returns: object - self

data(data) ⇒ object

set the data for the request

Kind: global function
Returns: object - self

ParamTypeDescription
dataobjectdata as json object

addHeader(key, value) ⇒ object

add a header

Kind: global function
Returns: object - self

ParamTypeDescription
keystringheader key
valuestringvalue of the header entry

allowUnauthorized() ⇒ object

Don't verifie against the list of supplied CAs.

Kind: global function
Returns: object - self

addAuthorizationHeader(authStr) ⇒ object

set a authorization header

Kind: global function
Returns: object - self

ParamTypeDescription
authStrstringauthirization string

setSendContentType(contentType) ⇒ object

set which type of format you want to send, default ist json

Kind: global function
Returns: object - self

ParamTypeDescription
contentTypeobjecta valid content type

sendsPlain() ⇒ object

function to send plain text to the server only make sense with post or put

Kind: global function
Returns: object - self

sendMultipart() ⇒ object

defines a multipart request for files, used with post() and data(filename)

Kind: global function
Returns: object - self

setBufferSize(bufferSize) ⇒ object

set the buffer size for a multipart request default is 4 * 1024

Kind: global function
Returns: object - self

ParamTypeDescription
bufferSizenumbersize in byte

setEncoding(encoding) ⇒ object

set the response encoding, default is utf-8

Kind: global function
Returns: object - self

ParamTypeDescription
encodingstringa valid encoding

expects(type) ⇒ object

set the format for the send callback, default is json

Kind: global function
Returns: object - self

ParamTypeDescription
typestringa valid content type

send(callback) ⇒ object

perform the previously created request

Kind: global function
Returns: object - self

ParamTypeDescription
callbackfunctionfunction called when the request is ready
0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago