Course
ai-dev-tools-zoomcamp
Question
When building the frontend-first full-stack application in Module 2, why should the frontend's API/service layer be used to define an OpenAPI contract before implementing the FastAPI backend?
Answer
The OpenAPI contract acts as the explicit agreement between the frontend and backend.
When the frontend is built first with a centralized service layer, the API requirements are already visible: endpoints, HTTP methods, request bodies, response bodies, and authentication requirements. Converting these requirements into openapi.yaml gives the backend a precise target instead of requiring the coding agent to infer the API from frontend code.
This makes the frontend and backend independently implementable while keeping their interface stable. It also reduces ambiguity and helps catch mismatches before the real backend is connected.
A typical workflow in Module 2 is:
- Build the interactive frontend with mocked backend calls.
- Centralize all backend calls in a frontend service layer.
- Generate an OpenAPI contract from that service layer.
- Implement the FastAPI backend against the contract.
- Replace the mocked service with the real backend client.
The contract is therefore not just documentation; it is the shared interface that allows the frontend and backend to evolve independently without guessing each other's requirements.
Checklist
Course
ai-dev-tools-zoomcamp
Question
When building the frontend-first full-stack application in Module 2, why should the frontend's API/service layer be used to define an OpenAPI contract before implementing the FastAPI backend?
Answer
The OpenAPI contract acts as the explicit agreement between the frontend and backend.
When the frontend is built first with a centralized service layer, the API requirements are already visible: endpoints, HTTP methods, request bodies, response bodies, and authentication requirements. Converting these requirements into
openapi.yamlgives the backend a precise target instead of requiring the coding agent to infer the API from frontend code.This makes the frontend and backend independently implementable while keeping their interface stable. It also reduces ambiguity and helps catch mismatches before the real backend is connected.
A typical workflow in Module 2 is:
The contract is therefore not just documentation; it is the shared interface that allows the frontend and backend to evolve independently without guessing each other's requirements.
Checklist