Skip to content

Instantly share code, notes, and snippets.

@devreena03
Created September 2, 2021 13:05
Show Gist options
  • Save devreena03/85ee68fff3e8fe45c019591ab7795ce6 to your computer and use it in GitHub Desktop.
Save devreena03/85ee68fff3e8fe45c019591ab7795ce6 to your computer and use it in GitHub Desktop.
### 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