Skip to content

Instantly share code, notes, and snippets.

@tomac
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save tomac/ac17c37e7f1ae6f51afc to your computer and use it in GitHub Desktop.

Select an option

Save tomac/ac17c37e7f1ae6f51afc to your computer and use it in GitHub Desktop.
var options = {
'hostname': config.API_HOST.hostname,
'port': config.API_HOST.port,
'path': queryString,
'method': HTTPMethod,
'headers': headers,
'protocol': config.API_HOST.protocol
};
var latchResponse = '';
var req = (options.protocol == 'http:' ? http : https).request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
latchResponse += chunk;
});
res.on('end', function() {
try {
var jsonresponse = JSON.parse(latchResponse);
} catch (e) {
next(new Error('problem with JSON parse: ' + e.message));
}
next(null, jsonresponse);
});
});
req.on('error', function(e) {
next(new Error('problem with request: ' + e.message));
});
req.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment