RSS

Fluent Request Builder for Node JS

25 Jan

It’s on my github page, so get it from there.
https://github.com/cairey/FluentRequestBuilder

The http lib can be a bit low level sometimes, so why not make it simpler. Use like so:

var requestBuilder = require('./requestBuilder');

var data = JSON.stringify({ 'important': 'data' });

var headers = {
'Host': 'www.example.com',
'Cookie': null,
'Content-Type': 'text/plain',
'Content-Length': Buffer.byteLength(data, 'utf8'),
'Accept': '*/*'
};

requestBuilder.withHeaders(headers)
.withData(data)
.withPort(80)
.makeRequest('http://google.com', '/', function(body, response){
console.write(body);
});

Advertisements
 
Leave a comment

Posted by on January 25, 2012 in JavaScript, Node, Software Development

 

Tags: , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: