Skip to main content

Chapter 67 — FastAPI: Your First Web API

The SmartNotes CLI works for James. He types commands in a terminal and gets results. But what about a mobile app? A browser? A chatbot? CLI tools require a terminal. Web APIs work everywhere. This chapter teaches you to expose SmartNotes over HTTP so any program, on any device, can add notes, search them, and export data.

FastAPI is the natural fit: it uses the typed Pydantic models you already know (Ch 55), it is async-native (Ch 66), and it auto-generates interactive documentation. You will build 3-4 routes, test them with TestClient, and see your notes in a browser for the first time.

#LessonFocusSmartNotes Deliverable
1What Is a Web API?HTTP methods, URLs, status codes (conceptual)None (vocabulary building)
2Hello FastAPIFastAPI app, route decorator, uvicorn, /docs UIGET / health endpoint
3Request and Response ModelsPydantic request/response schemas, POST route, 422 validationPOST /notes with NoteCreate/NoteResponse models
4Path Parameters and SearchPath params, query params, route orderingGET /notes/{id}, GET /notes/search
5Testing with TestClientTestClient, TDG for API routesTest suite for all routes
6SmartNotes API CapstoneFull TDG: complete API with search and exportGET/POST, search, export endpoints

Prerequisites: Async Python (Ch 66 for async def routes), Pydantic BaseModel (Ch 55), pytest (Ch 52), SmartNotes package (Ch 63).