Created
September 2, 2021 13:05
-
-
Save devreena03/85ee68fff3e8fe45c019591ab7795ce6 to your computer and use it in GitHub Desktop.
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
### Javascript | |
var requestOptions = { | |
method: 'GET', | |
redirect: 'follow' | |
}; | |
fetch("https://jsonmock.hackerrank.com/api/movies?Year=1999", requestOptions) | |
.then(response => response.text()) | |
.then(result => console.log(result)) | |
.catch(error => console.log('error', error)); | |
### Node - core | |
var https = require('follow-redirects').https; | |
var fs = require('fs'); | |
var options = { | |
'method': 'GET', | |
'hostname': 'jsonmock.hackerrank.com', | |
'path': '/api/movies?Year=1999', | |
'headers': { | |
}, | |
'maxRedirects': 20 | |
}; | |
var req = https.request(options, function (res) { | |
var chunks = []; | |
res.on("data", function (chunk) { | |
chunks.push(chunk); | |
}); | |
res.on("end", function (chunk) { | |
var body = Buffer.concat(chunks); | |
console.log(body.toString()); | |
}); | |
res.on("error", function (error) { | |
console.error(error); | |
}); | |
}); | |
### node - request | |
var request = require('request'); | |
var options = { | |
'method': 'GET', | |
'url': 'https://jsonmock.hackerrank.com/api/movies?Year=1999', | |
'headers': { | |
} | |
}; | |
request(options, function (error, response) { | |
if (error) throw new Error(error); | |
console.log(response.body); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment