From a80351816cb8b2e55d0452a58e5cb5a0e693da86 Mon Sep 17 00:00:00 2001 From: Alex-Pro-commit <73656348+Alex-Pro-commit@users.noreply.github.com> Date: Sun, 31 Oct 2021 14:55:52 -0400 Subject: [PATCH] Finished the Api Lab --- package-lock.json | 3 +++ zip-api/app.js | 26 +++++++++++--------------- zip-api/package.json | 34 +++++++++++++++++----------------- 3 files changed, 31 insertions(+), 32 deletions(-) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..48e341a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +} diff --git a/zip-api/app.js b/zip-api/app.js index df1f97b..fc596a3 100644 --- a/zip-api/app.js +++ b/zip-api/app.js @@ -1,29 +1,25 @@ -const express = require('express'); +const express = require("express"); const app = express(); - -const zipdb = require('./zipData'); +// imports csv in the data folder +const zipdb = require("./zipData"); const PORT = process.env.PORT || 8000; - // console.log(zipdb.byCity); - -app.get('/', (req, res) => { - res.json({test: 'Yay'}); +app.get("/", (req, res) => { + res.json({ test: "Yay" }); }); - -app.get('/zip/:zipcode', (req, res) => { - // fill in... +app.get("/zip/:zipcode", (req, res) => { + res.send(zipdb.byZip[req.params.zipcode]); }); - -app.get('/city/:cityname', (req, res) => { - // fill in... +app.get("/city/:cityname", (req, res) => { + res.send(zipdb.byCity[req.params.cityname]); }); - +// the keys are upper case like BROOKLYN app.listen(PORT, () => { - console.log(`zip-api is up and running on ${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..8cecf59 100644 --- a/zip-api/package.json +++ b/zip-api/package.json @@ -1,19 +1,19 @@ { - "name": "zip-api", - "version": "1.0.0", - "description": "Simple API backend for CTP lecture.", - "main": "app.js", - "scripts": { - "start": "node app.js" - }, - "author": "Edgardo Molina", - "license": "ISC", - "dependencies": { - "csv-parse": "^4.12.0", - "express": "^4.17.1", - "morgan": "^1.10.0" - }, - "devDependencies": { - "nodemon": "^1.19.4" - } + "name": "zip-api", + "version": "1.0.0", + "description": "Simple API backend for CTP lecture.", + "main": "app.js", + "scripts": { + "start": "node app.js" + }, + "author": "Edgardo Molina", + "license": "ISC", + "dependencies": { + "csv-parse": "^4.12.0", + "express": "^4.17.1", + "morgan": "^1.10.0" + }, + "devDependencies": { + "nodemon": "^1.19.4" + } }