Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
# Zip Code API Lab
# Zip Code API 🔥

## Project 00: Hello World in Express.js
## 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 the specified zipcode or city.

> Note: you do not have to hand this in.
![Demo](https://i.imgur.com/R9qOpqR.gif)

## Project 01: Build the Zip API service

This week we will build the Zip code API that we used last week in-class.
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

> 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
```
http://localhost:8000/zip/42069
```
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":""
}]
```


> 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/
Expand Down
18 changes: 16 additions & 2 deletions zip-api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,26 @@ app.get('/', (req, res) => {


app.get('/zip/:zipcode', (req, res) => {
// fill in...
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;
let response = zipdb.byCity[city];
if(response === undefined){
res.status(404).send('ERROR 404, CITY NOT FOUND');
}else{
res.json(response);
}

});


Expand Down
4 changes: 2 additions & 2 deletions zip-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "Simple API backend for CTP lecture.",
"main": "app.js",
"scripts": {
"start": "node app.js"
"start": "nodemon app.js"
},
"author": "Edgardo Molina",
"author": "Mohammed Chowdhurys",
"license": "ISC",
"dependencies": {
"csv-parse": "^4.12.0",
Expand Down