Skip to content

Instantly share code, notes, and snippets.

@aj07mm
Created January 15, 2016 18:28
Show Gist options
  • Save aj07mm/f696bebc4aed96fe522b to your computer and use it in GitHub Desktop.
Save aj07mm/f696bebc4aed96fe522b to your computer and use it in GitHub Desktop.
GET request call http/https nodejs
var https = require('https'),
http = require('http'),
optionsget = {
host : 'maps.googleapis.com', // here only the domain name
path : '/maps/api/directions/json?origin=Toledo&destination=Madrid&region=es&key=key', // the rest of the url with parameters if needed
method : 'GET', // do GET
json:true
};
// do the GET request
var reqGet = https.request(optionsget, function(res) {
res.on('data', function(d) {
process.stdout.write(d);
});
});
reqGet.end();
reqGet.on('error', function(e) {
console.error(e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment