Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
HTTP API GET in node.js
http.get(endpoint + queryString, function (res) {
var noaaResponseString = '';
if (res.statusCode != 200) {
tideResponseCallback(new Error("Non 200 Response"));
}
res.on('data', function (data) {
noaaResponseString += data;
});
res.on('end', function () {
var noaaResponseObject = JSON.parse(noaaResponseString);
if (noaaResponseObject.error) {
console.log("NOAA error: " + noaaResponseObj.error.message);
tideResponseCallback(new Error(noaaResponseObj.error.message));
} else {
var highTide = findHighTide(noaaResponseObject);
tideResponseCallback(null, highTide);
}
});
}).on('error', function (e) {
console.log("Communications error: " + e.message);
tideResponseCallback(new Error(e.message));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment