Created
October 23, 2018 12:15
-
-
Save ronaldronson/08b2f058553c94e8054e10b7dab8460d to your computer and use it in GitHub Desktop.
Node request with promises.
This file contains 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
const http = require('http') | |
function makeCall(options) { | |
return new Promise(function(resolve, reject) { | |
const req = http.request(options, (res) => { | |
const q = [] | |
res.setEncoding('utf8') | |
res.on('data', (chunk) => q.push(chunk)) | |
res.on('end', () => resolve(q.join(''))) | |
}) | |
req.on('error', (e) => reject(e)) | |
req.write('') // pass requrst body here | |
req.end() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment