Skip to content

Instantly share code, notes, and snippets.

@mosampaio
Created August 22, 2016 17:05
Show Gist options
  • Save mosampaio/897d484d290e82d52602ee2fc70cdbc6 to your computer and use it in GitHub Desktop.
Save mosampaio/897d484d290e82d52602ee2fc70cdbc6 to your computer and use it in GitHub Desktop.
How to consume a json Rest API with Node.js using Request
// install the dependency > npm install request
const request = require('request');
const opts = {
uri: 'https://api.github.com/repos/twilio/twilio-node/contributors',
headers: {'user-agent': 'My App'}
};
request(opts, (error, response, body) => {
if (error) {
return console.log('error on request: ' + error);
} else {
console.log(JSON.parse(body));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment