This project provides a REST API to generate and serve a report on the qualification results of the Monaco 2018 Grand Prix in Formula 1. The API supports JSON and XML response formats and stores the data in an SQLite database using Peewee ORM.
The project uses Flask, Flask-RESTful, Peewee, Flasgger (Swagger) for interactive API documentation, and pytest for unit testing.
Clone the Repository
cd existing_repo
git remote add origin https://github.com/Aleksandr-ln/rest-api-f1-race-db-report.git
git branch -M main
git push -uf origin main
python -m venv venv
source venv/bin/activate # For macOS/Linux
source venv/Scripts/activate # For Git Bash
venv\Scripts\activate # For Windows
pip install -r requirements.txt
export PYTHONPATH=$(pwd)/..
python -m database.setup_db
export PYTHONPATH=$(pwd)/..
python race_report_api.py
The API will be available at: http://localhost:5000/api/v1/report/?event=Monaco%202018%20Grand%20Prix&session=Qualification
eventandsessionparameters must correspond to existing records in the database.- Available
format:json(default),xml.
curl -X GET "http://localhost:5000/api/v1/report/?event=Monaco%202018%20Grand%20Prix&session=Qualification&format=json"
curl -X GET "http://localhost:5000/api/v1/report/?event=Monaco%202018%20Grand%20Prix&session=Qualification&format=xml"
| Field | Type | Description |
|---|---|---|
| id | AutoField | Primary key |
| abbreviation | CharField | Driver abbreviation (unique, 3 letters) |
| full_name | CharField | Full name of driver |
| team | CharField | Team name |
| Field | Type | Description |
|---|---|---|
| id | AutoField | Primary key |
| driver | ForeignKeyField | Reference to Driver |
| event | CharField | Name of race event (e.g., Monaco 2018 GP) |
| session | CharField | Name of session (e.g., Qualification) |
| date | DateField | Date of the event |
| start_time | DateTimeField | Start time of race/session (nullable) |
| end_time | DateTimeField | End time of race/session (nullable) |
- Composite Unique Index on
(driver, event, session)to prevent duplicates.
{
"race": "Monaco 2018 Grand Prix - Qualification",
"date": "2018-05-24",
"results": [
{
"position": 1,
"driver": "Sebastian Vettel",
"team": "FERRARI",
"lap_time": "1:04.415"
}
],
"disqualified": [
{
"position": 16,
"driver": "Lewis Hamilton",
"team": "MERCEDES",
"lap_time": "-7:12.460"
}
]
}
This project includes an interactive API documentation using Swagger UI.
To access the documentation, run the API server and navigate to:
http://localhost:5000/apidocs/#/default/get_api_v1_report_
- Open Swagger UI in your browser.
- Select the
GET /api/v1/report/endpoint. - Choose a response format (
jsonorxml). - Click Execute to send the request.
- View the response directly in the UI.
This project includes unit tests to validate the API's functionality and report generation.
coverage run -m pytest tests/
coverage report -m
- Flask – Web framework for building the API
- Flask-RESTful – Extension for building RESTful APIs
- Flasgger – Automatic Swagger documentation generation
- pytest – Unit testing framework
- dataclasses – Structured data representation
- xml.etree.ElementTree – XML conversion
- bs4 (BeautifulSoup) – XML parsing in tests
Oleksandr Onupko