This project implements the IHR API, migrating from the old API system to a more efficient architecture. It introduces a new database management system using Alembic and enhances the structure for creating new endpoints. The API is built on FastAPI and can be run in either a Python virtual environment or using Docker.
git clone https://github.com/InternetHealthReport/ihr-api.git
In the project root directory, create a new .env
file to define your specific database connection string, proxy path and page size (number of results to return per page.).
.env
content:
DATABASE_URL=postgresql://<username>:<password>@<host>:<port>/<database>
PROXY_PATH=api-dev
PAGE_SIZE=100000
You can run this application in one of the following ways:
- Using a Python virtual environment
- Using Docker
python -m venv venv
venv\Scripts\activate
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
docker build -t ihr-api .
docker run --name ihr-api -p 8000:8000 -d --env-file .env ihr-api
docker run --name ihr-api --env-file .env --restart unless-stopped -p 8000:8000 -d -t internethealthreport/ihr-api:v{v_number}
Where v_number
is the version number.
Start an existing container:
docker start <container-id>
View logs:
docker logs -f <container-id>
Once running, you can access:
- API: http://localhost:8000
- Interactive Docs (Swagger UI): http://localhost:8000/docs
The docs/
folder contains detailed documentation for various aspects of the project. Below is a list of available documentation files and their descriptions:
Provides an overview of the project's file and folder structure, organized according to the Service-Controller-Repository architectural pattern.
Explains the Service-Controller-Repository architecture adopted by the project, highlighting the responsibilities of each layer and how they interact.
Details how to manage database migrations using Alembic, including TimescaleDB-specific features like hypertables and compression policies.
A step-by-step guide on how to add a new endpoint to the application.