Created
August 11, 2020 14:49
-
-
Save nataliaconde/1486269165b8ee6b37a4d01b9cc7995c to your computer and use it in GitHub Desktop.
Building the External API Cal
This file contains 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
var request = require('request'); | |
const apiKey = process.env.ZIPCODE_API_KEY || "hkCt1nW1wF1rppaEmoor7T9G4ta7R5wFSu8l1dokNz8y53gGZHDneWWVosbEYirC"; | |
const zipCodeURL = 'https://www.zipcodeapi.com/rest/'; | |
var distance = { | |
find: function(req, res, next) { | |
request(zipCodeURL + apiKey | |
+ '/distance.json/' + req.params.zipcode1 + '/' | |
+ req.params.zipcode2 + '/mile', | |
function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
response = JSON.parse(body); | |
res.send(response); | |
} else { | |
console.log(response.statusCode + response.body); | |
res.send({distance: -1}); | |
} | |
}); | |
} | |
}; | |
module.exports = distance; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment