diff --git a/zip-api/app.js b/zip-api/app.js index df1f97b..7317631 100644 --- a/zip-api/app.js +++ b/zip-api/app.js @@ -16,11 +16,35 @@ app.get('/', (req, res) => { app.get('/zip/:zipcode', (req, res) => { // fill in... + + const zipcode = req.params.zipcode; + + if (zipcode.length !== 5) { + req.status(404).send("404 Not Found"); + } + else { + res.json({ + zipCode: zipcode, + data: zipdb.byZip[zipcode] + }) + } }); app.get('/city/:cityname', (req, res) => { // fill in... + + const city = req.params.cityname.toUpperCase(); + + if (city === undefined) { + req.status(404).send("404 Not Found"); + } + else { + res.json({ + cityName: city, + data: zipdb.byCity[city] + }) + } });