From d755faf195d3022851b8c63f80313338251b3843 Mon Sep 17 00:00:00 2001 From: tasnimul2 Date: Mon, 25 Oct 2021 13:33:16 -0400 Subject: [PATCH 1/8] api responds with json --- zip-api/app.js | 4 ++++ zip-api/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/zip-api/app.js b/zip-api/app.js index df1f97b..de17c72 100644 --- a/zip-api/app.js +++ b/zip-api/app.js @@ -16,11 +16,15 @@ app.get('/', (req, res) => { app.get('/zip/:zipcode', (req, res) => { // fill in... + let zip = req.params.zipcode + res.json(zipdb.byZip[zip]); }); app.get('/city/:cityname', (req, res) => { // fill in... + let city = req.params.cityname; + res.json(zipdb.byCity[city]); }); 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", From be1b0b36e490f9e42d798b022f1c3d6f079b8335 Mon Sep 17 00:00:00 2001 From: tasnimul2 Date: Mon, 25 Oct 2021 14:02:13 -0400 Subject: [PATCH 2/8] zip-code api lab done --- zip-api/app.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/zip-api/app.js b/zip-api/app.js index de17c72..a14a07b 100644 --- a/zip-api/app.js +++ b/zip-api/app.js @@ -16,15 +16,27 @@ app.get('/', (req, res) => { app.get('/zip/:zipcode', (req, res) => { // fill in... - let zip = req.params.zipcode - res.json(zipdb.byZip[zip]); + let zip = req.params.zipcode; + let response = zipdb.byZip[zip]; + + if(response === undefined){ + res.status(404).send('ERROR 404, ZIPCODE NOT FOUND'); + }else{ + res.json(response); + } }); app.get('/city/:cityname', (req, res) => { // fill in... let city = req.params.cityname; - res.json(zipdb.byCity[city]); + let response = zipdb.byCity[city]; + if(response === undefined){ + res.status(404).send('ERROR 404, CITY NOT FOUND'); + }else{ + res.json(response); + } + }); From f22f230f6294563d01a4aec68120feebfc4b490e Mon Sep 17 00:00:00 2001 From: Tasnimul Chowdhury <41757010+tasnimul2@users.noreply.github.com> Date: Fri, 12 Nov 2021 15:46:10 -0500 Subject: [PATCH 3/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c1b376b..8bd9b6a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Zip Code API Lab +# Zip Code API Lab 🔥 ## Project 00: Hello World in Express.js From f187e9ec2197409a08bd4dc6c5b678e3d83db5f8 Mon Sep 17 00:00:00 2001 From: Tasnimul Chowdhury <41757010+tasnimul2@users.noreply.github.com> Date: Fri, 12 Nov 2021 15:58:13 -0500 Subject: [PATCH 4/8] Update README.md --- README.md | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8bd9b6a..cf6ee63 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,46 @@ -# Zip Code API Lab 🔥 +# Zip Code API 🔥 -## Project 00: Hello World in Express.js +## Project 01: Build the Zip API service -Follow instructions in class to create an npm project from scratch, and make a simple hello world web app using Express.js. +The Zip Code API , when called, returns a json object with information regarding that particual zipcode or city. -> Note: you do not have to hand this in. +Ex. Doing -## Project 01: Build the Zip API service +http://ctp-zip-api.herokuapp.com/zip/42069 + +or if you want to run locally after cloning this repo + +http://localhost:8000/zip/42069 + +will output : +``` +[{ +"RecordNumber":"23208", +"Zipcode":"42069", +"ZipCodeType":"STANDARD", +"City":"MELBER", +"State":"KY", +"LocationType":"PRIMARY", +"Lat":"36.91", +"Long":"-88.75", +"Xaxis":"0.01", +"Yaxis":"-0.79", +"Zaxis":"0.60", +"WorldRegion":"NA", +"Country":"US", +"LocationText":"Melber, KY", +"Location":"NA-US-KY-MELBER", +"Decommisioned":"false", +"TaxReturnsFiled":"421", +"EstimatedPopulation":"807", +"TotalWages":"10888387", +"Notes":"" +}] +``` -This week we will build the Zip code API that we used last week in-class. -> Note: The documentation for the API can be found here: https://github.com/CUNYTechPrep/zip-code-react-lab#the-zip-and-city-search-api-documentation-ctp-zip-api +> Note: http://ctp-zip-api.herokuapp.com/ is the URL for the API to be used in your app. +> To run the program on your local device, clone this repo and : - `cd zip-api` - `npm install` From 03a5532872a4a0fe0d437da4004e066e804b140f Mon Sep 17 00:00:00 2001 From: Tasnimul Chowdhury <41757010+tasnimul2@users.noreply.github.com> Date: Fri, 12 Nov 2021 15:58:41 -0500 Subject: [PATCH 5/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf6ee63..6c49ca2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Zip Code API 🔥 -## Project 01: Build the Zip API service +## the Zip API service The Zip Code API , when called, returns a json object with information regarding that particual zipcode or city. From 7659862b6457c1dd46d8071977b2e34c212aefcd Mon Sep 17 00:00:00 2001 From: Tasnimul Chowdhury <41757010+tasnimul2@users.noreply.github.com> Date: Fri, 12 Nov 2021 16:35:24 -0500 Subject: [PATCH 6/8] Update README.md --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6c49ca2..df210e1 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,19 @@ The Zip Code API , when called, returns a json object with information regarding that particual zipcode or city. -Ex. Doing +![Demo](https://i.imgur.com/R9qOpqR.gif) -http://ctp-zip-api.herokuapp.com/zip/42069 +Example of how to call the API +``` +http://ctp-zip-api.herokuapp.com/zip/42069 +``` or if you want to run locally after cloning this repo +``` http://localhost:8000/zip/42069 - -will output : +``` +Output : ``` [{ "RecordNumber":"23208", @@ -40,11 +44,12 @@ will output : > Note: http://ctp-zip-api.herokuapp.com/ is the URL for the API to be used in your app. + > To run the program on your local device, clone this repo and : - `cd zip-api` - `npm install` -- Add the code for the `/zip` and `/city` routes +- read the code for the `/zip` and `/city` routes to understand how the API calls and responses are being made - `npm start` to start dev server - Visit: + http://localhost:8000/ From 582a2c013aa7bf17e2351e5545eaeaab8a2c47a9 Mon Sep 17 00:00:00 2001 From: tasnimul2 Date: Fri, 12 Nov 2021 16:38:28 -0500 Subject: [PATCH 7/8] api complete --- zip-api/app.js | 2 -- zip-api/package.json | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/zip-api/app.js b/zip-api/app.js index a14a07b..bf88de9 100644 --- a/zip-api/app.js +++ b/zip-api/app.js @@ -15,7 +15,6 @@ app.get('/', (req, res) => { app.get('/zip/:zipcode', (req, res) => { - // fill in... let zip = req.params.zipcode; let response = zipdb.byZip[zip]; @@ -28,7 +27,6 @@ app.get('/zip/:zipcode', (req, res) => { app.get('/city/:cityname', (req, res) => { - // fill in... let city = req.params.cityname; let response = zipdb.byCity[city]; if(response === undefined){ diff --git a/zip-api/package.json b/zip-api/package.json index 0ae0f49..32e33ca 100644 --- a/zip-api/package.json +++ b/zip-api/package.json @@ -6,7 +6,7 @@ "scripts": { "start": "nodemon app.js" }, - "author": "Edgardo Molina", + "author": "Mohammed Chowdhurys", "license": "ISC", "dependencies": { "csv-parse": "^4.12.0", From 87f6214cb34702f2ec402d0f82f1bcd9f9ca96f1 Mon Sep 17 00:00:00 2001 From: tasnimul2 Date: Fri, 12 Nov 2021 17:58:32 -0500 Subject: [PATCH 8/8] readme updated --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index df210e1..2a53cc5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## the Zip API service -The Zip Code API , when called, returns a json object with information regarding that particual zipcode or city. +The Zip Code API , when called, returns a json object with information regarding the specified zipcode or city. ![Demo](https://i.imgur.com/R9qOpqR.gif)