Use Case 1: Quickstart โ Build Your First OpenAPI-First Service
This guide walks you from an empty directory to a running, contract-driven service in a few minutes, then talks to it with the generated client.
๐ ๏ธ 1. Prerequisites
- Python 3.10+
openapi-firstinstalled (see Overview)pip install "fastapi[standard]"(oruvicorn) to run the app
๐ 2. Write the OpenAPI document
OpenAPI comes first. Create openapi.yaml:
Key points: every operation needs operationId, and every route must exist only here.
๐งโ๐ป 3. Write the handlers
Create routes.py โ plain functions, no decorators, named exactly like the operationIds:
If a handler is missing at startup, the app refuses to boot (MissingOperationHandler) โ the fail-fast guarantee catches contract drift immediately.
๐ 4. Bootstrap the app
Create main.py:
Run it:
Visit http://localhost:8000/docs (Swagger UI) and http://localhost:8000/openapi.json โ both are generated from your spec.
๐ก 5. Call it with the client
The same spec builds a strict client:
๐ก 6. Next Steps
- Copy a fuller example: 02 โ Templates
- Generate models/routes from a bigger spec: 04 โ Codegen
- Drive everything from a client: 03 โ Client