|
| 1 | +# fastapi-basic |
| 2 | + |
| 3 | +A minimal FastAPI "Hello, World!" service, managed with [uv](https://docs.astral.sh/uv/). |
| 4 | + |
| 5 | +This `main` branch contains only the app and local dev setup. Deployment is demonstrated on two separate branches: |
| 6 | + |
| 7 | +- **[`deploy-script`](../../tree/deploy-script)** — deploy with a local `gcloud` script ([deploy.sh](deploy.sh)). |
| 8 | +- **[`deploy-github`](../../tree/deploy-github)** — deploy from GitHub via a GitHub Actions workflow. |
| 9 | + |
| 10 | +## Stack |
| 11 | + |
| 12 | +- Python 3.13 |
| 13 | +- FastAPI + Uvicorn (standard) |
| 14 | +- uv for dependency / venv management |
| 15 | +- Docker (python:3.13-slim + uv binary from `ghcr.io/astral-sh/uv`) |
| 16 | + |
| 17 | +## Project layout |
| 18 | + |
| 19 | +``` |
| 20 | +. |
| 21 | +├── main.py # FastAPI app (/, /healthz) |
| 22 | +├── pyproject.toml # project metadata + deps |
| 23 | +├── uv.lock # locked dependency graph |
| 24 | +├── .python-version # pins Python 3.13 for uv |
| 25 | +├── Dockerfile # uv-based container build |
| 26 | +└── .dockerignore |
| 27 | +``` |
| 28 | + |
| 29 | +## Endpoints |
| 30 | + |
| 31 | +| Method | Path | Response | |
| 32 | +| ------ | ----------- | ------------------------------ | |
| 33 | +| GET | `/` | `{"message": "Hello, World!"}` | |
| 34 | +| GET | `/healthz` | `{"status": "ok"}` | |
| 35 | +| GET | `/docs` | Swagger UI | |
| 36 | +| GET | `/redoc` | ReDoc UI | |
| 37 | + |
| 38 | +## Prerequisites |
| 39 | + |
| 40 | +- [uv](https://docs.astral.sh/uv/getting-started/installation/) (`brew install uv`) |
| 41 | +- Docker (only if you want to build/run the container locally) |
| 42 | + |
| 43 | +## Local development |
| 44 | + |
| 45 | +```bash |
| 46 | +uv sync |
| 47 | +uv run uvicorn main:app --reload --port 8080 |
| 48 | +``` |
| 49 | + |
| 50 | +Then: |
| 51 | + |
| 52 | +```bash |
| 53 | +curl http://localhost:8080/ |
| 54 | +curl http://localhost:8080/healthz |
| 55 | +open http://localhost:8080/docs |
| 56 | +``` |
| 57 | + |
| 58 | +### Managing dependencies |
| 59 | + |
| 60 | +```bash |
| 61 | +uv add <package> # add a runtime dep |
| 62 | +uv add --dev <package> # add a dev-only dep |
| 63 | +uv remove <package> # remove a dep |
| 64 | +uv lock --upgrade # refresh uv.lock |
| 65 | +``` |
| 66 | + |
| 67 | +## Run with Docker |
| 68 | + |
| 69 | +```bash |
| 70 | +docker build -t fastapi-basic . |
| 71 | +docker run --rm -p 8080:8080 fastapi-basic |
| 72 | +``` |
| 73 | + |
| 74 | +The image installs deps with `uv sync --frozen --no-dev` against `uv.lock`, so the container matches local exactly. |
| 75 | + |
| 76 | +## Deploying |
| 77 | + |
| 78 | +Check out one of the deploy branches: |
| 79 | + |
| 80 | +```bash |
| 81 | +git checkout deploy-script # local gcloud-based deploy |
| 82 | +# or |
| 83 | +git checkout deploy-github # GitHub Actions deploy |
| 84 | +``` |
0 commit comments