A simple Flask API built on the NYC "Leading Causes of Death" dataset.
Supports listing records, filtering by column, pagination (limit/offset), retrieving a single record by id, and output in JSON or CSV. Remember to use the pretty-print button otherwise it would look a bit messy.
This API runs locally. Access it at:
Make sure the server is running before sending requests.
- Create virtual environment
python -m venv venv
- Activate environment
Mac/Linux: source venv/bin/activate
- Install requirements
pip install -r requirements.txt
- Run the server
python project.py
- Method: GET
- Path: /
- Query parameters: None
Returns a welcome message.
Example: GET /
Response: "NYC Death Causes API is running."
- Method: GET
- Path: /records
- Query parameters:
- format (optional): json or csv (default: json)
- limit (optional): number of results to return
- offset (optional): starting index for pagination
- filters (optional): any column name in the dataset, e.g. Year=2021, Sex=Female
Example query: http://127.0.0.1:5000/records?Sex=Female&Year=2021&limit=5&offset=0&format=json
Sample output (JSON): [ { "Year": 2021, "Leading Cause": "Diseases of Heart (I00-I09, I11, I13, I20-I51)", "Sex": "Female", "Race Ethnicity": "Hispanic", "Deaths": "1409", "Death Rate": "111", "Age Adjusted Death Rate": null, "id": 0 } ]
You can filter by any column name in the dataset.
Examples:
- /records?Sex=Female
- /records?Year=2021
- /records?Race Ethnicity=Hispanic
- limit: number of records to return
- offset: starting index
Examples:
- /records?limit=5
- /records?limit=5&offset=10
- /records?Sex=Female&limit=3
- format=json (default)
- format=csv
Example:
- /records?limit=5&format=csv
- Method: GET
- Path: /records/
- Query parameters: None
Example query: http://127.0.0.1:5000/records/10