Last active
October 24, 2016 02:17
-
-
Save gjyoung1974/1d429b0ebefa6a84f7fcfc5b8e619b51 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
//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