Skip to content

Instantly share code, notes, and snippets.

@mosampaio
Created August 22, 2016 17:03
Show Gist options
  • Save mosampaio/fb29871b2e2957209c74ea1efa5897c0 to your computer and use it in GitHub Desktop.
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
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