Created
October 10, 2018 07:21
-
-
Save valerianpereira/9ec2c0eabd5bb227aeb285afb151bb57 to your computer and use it in GitHub Desktop.
Making an API call in NodeJs using https package
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 https = require('https'); | |
const URL = 'You can find http API url from https://indianrailapi.com/api-collection'; | |
https.get(URL, (resp) => { | |
let data = ''; | |
// A chunk of data has been recieved. | |
resp.on('data', (chunk) => { | |
data += chunk; | |
}); | |
// The whole response has been received. Print out the result. | |
resp.on('end', () => { | |
console.log(JSON.parse(data)); | |
}); | |
}).on("error", (err) => { | |
console.error("Error: " + err.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment