A minimal FastAPI application that implements JWT-based authentication. Your goal is to get it running correctly and verify that every endpoint responds as documented below.
| Tool | Install |
|---|---|
uv |
curl -LsSf https://astral.sh/uv/install.sh | sh |
| Docker + Compose plugin | Official Docker docs |
# 1. Generate / refresh the dependency lock file
uv lock
# 2. Build the image and start the container
docker compose up --buildThe API will be available at http://localhost:8000.
# Install the virtual environment
uv sync
# Start the development server
uv run uvicorn main:app --app-dir src --host 0.0.0.0 --port 8000 --reloadAll examples assume the service is reachable at http://localhost:8000.
curl -s http://localhost:8000/
# Expected → {"message":"Hello, World!"}curl -s -X POST http://localhost:8000/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=john_doe&password=password"
# Expected → {"access_token":"<token>","token_type":"bearer"}TOKEN=$(curl -s -X POST http://localhost:8000/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=john_doe&password=password" \
| jq -r .access_token)
curl -s http://localhost:8000/me \
-H "Authorization: Bearer $TOKEN"
# Expected → {"username":"john_doe"}| Method | Path | Auth | Description |
|---|---|---|---|
| GET | / |
— | Health check |
| POST | /token |
— | Exchange credentials for a JWT |
| GET | /me |
Bearer token | Return the authenticated user |