Created
August 22, 2016 17:03
-
-
Save mosampaio/fb29871b2e2957209c74ea1efa5897c0 to your computer and use it in GitHub Desktop.
How to consume a json Rest API with Node.js using Http module
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
const https = require('https'); | |
const opts = { | |
protocol: 'https:', | |
host: 'api.github.com', | |
path: '/repos/twilio/twilio-node/contributors', | |
headers: {'user-agent': 'My App'} | |
}; | |
https.get(opts, (res) => { | |
let data = ''; | |
res.on('data', (d) => { | |
data += d; | |
}); | |
res.on('end', () => { | |
console.log(JSON.parse(data)); | |
}); | |
}).on('error', (e) => { | |
console.error(e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment