HTTP.get()

Send a GET request and receive the response.

This machine is designed for making basic requests to a modern JSON API. For more flexibility, including more encoding options and the ability to attach custom request headers, use the lower-level machine: `sendHttpRequest()`.

Usage

Hover over inputs/exits for more info.

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


// Send a GET request and receive the response.

HTTP.get({

url: '/7/friends/search',

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

data: {},

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// A non-2xx status code was returned from the server.

non200Response: function (result) {

 

},

// Unexpected connection error: could not send or receive HTTP request.

requestFailed: function () {

 

},

// OK.

success: function (result) {

 

},

});

Inputs

url required

The URL where the request should be sent.

'/7/friends/search'
baseUrl

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

'api.example.com/pets'
data

Optional data to send with this request.

{}

Exits

error

An unexpected error occurred.

non200Response

A non-2xx status code was returned from the server.

{ statusCode: 404,
  headers: {},
  body: '...[{"maybe some JSON": "like this"}]  (but could be any string)' }
requestFailed

Unexpected connection error: could not send or receive HTTP request.

success

OK.

'*'