Created
August 22, 2016 17:05
-
-
Save mosampaio/897d484d290e82d52602ee2fc70cdbc6 to your computer and use it in GitHub Desktop.
How to consume a json Rest API with Node.js using Request
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
// 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