Skip to content

Instantly share code, notes, and snippets.

@gjyoung1974
Last active October 24, 2016 02:17
Show Gist options
  • Save gjyoung1974/1d429b0ebefa6a84f7fcfc5b8e619b51 to your computer and use it in GitHub Desktop.
Save gjyoung1974/1d429b0ebefa6a84f7fcfc5b8e619b51 to your computer and use it in GitHub Desktop.
//call a REST Api
var http = require('http');
var sAPIKey = '939f36408065e19b83f5f8352573257e'
var options = {
hostname: 'api.openweathermap.org',
port: 80,
path: '/data/2.5/weather?lat=33.265014&lon=-111.839105&appid=' + sAPIKey,
method: 'POST',
headers: {
'User-Agent': 'node.js',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
};
var req = http.request(options, function (res) {
//TODO do something with the headers:
// console.log('headers:\n' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('body:\n' + chunk);
});
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
});
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment