HTTP.getStream()

Send a GET request and immediately return the stream, which can be pumped to obtain the bytes of the response.

The responsibility for any other validations/error handling falls on the consumer of the stream. However, this method _DOES_ bind an `error` event handler on the stream to prevent emitted error events from crashing the process; ensuring that this method is agnostic of its userland environment. If you plan to write code which uses the readable stream returned by this method but you have never worked with Readable streams in Node.js, [check this out](https://docs.nodejitsu.com/articles/advanced/streams/how-to-use-fs-create-read-stream) for tips. For more conceptual information about readable streams in Node.js in general, check out the section on [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable) in the Node.js docs.

Usage

Hover over inputs/exits for more info.

var HTTP = require('machinepack-http');


// Send a GET request and immediately return the stream, which can be pumped to obtain the bytes of the response.

HTTP.getStream({

url: '/7/friends/search',

data: {},

headers: {},

baseUrl: 'api.example.com/pets',

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// OK.

success: function (result) {

 

},

});

Inputs

url required

The URL where the request should be sent.

'/7/friends/search'
data

Optional data to send with this request.

{}
headers

Custom headers to include in the request (e.g. {"X-Auth": "k3yboardc4t"}).

{}
baseUrl

An optional base URL to resolve the main `url` against.

'api.example.com/pets'

Exits

error

An unexpected error occurred.

success

OK.

'==='