Last active
August 29, 2015 14:04
-
-
Save tomac/ac17c37e7f1ae6f51afc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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