diff --git a/zip-api/app.js b/zip-api/app.js index df1f97b..7475370 100644 --- a/zip-api/app.js +++ b/zip-api/app.js @@ -13,17 +13,32 @@ app.get('/', (req, res) => { res.json({test: 'Yay'}); }); - app.get('/zip/:zipcode', (req, res) => { - // fill in... + // get city data from zipData + const zips = zipdb.byZip[req.params.zipcode]; + + // if zipcodes exist, return city data + // else return 'not found' status code + if(zips) { + res.json(zips); + } else { + res.sendStatus('404'); + } }); - app.get('/city/:cityname', (req, res) => { - // fill in... + // get zipcode data from zipData + const cities = zipdb.byCity[req.params.cityname.toUpperCase()]; + + // if city exist, return zipcode info + // else return 'not found' status code + if(cities) { + res.json(cities); + } else { + res.sendStatus('404'); + } }); - app.listen(PORT, () => { console.log(`zip-api is up and running on ${PORT}`); }); diff --git a/zip-api/package.json b/zip-api/package.json index 631bb53..0ae0f49 100644 --- a/zip-api/package.json +++ b/zip-api/package.json @@ -4,7 +4,7 @@ "description": "Simple API backend for CTP lecture.", "main": "app.js", "scripts": { - "start": "node app.js" + "start": "nodemon app.js" }, "author": "Edgardo Molina", "license": "ISC",