Response model
In FastAPI, the class that describes a reply: only its fields are sent, so internal data such as password hashes can't leak out.
The return annotation
-> HikeOutis the response model: FastAPI converts the result to that shape and sends only its fields. That's an important safety net. If a database row has apassword_hashcolumn and the response model doesn't, the hash can never leak into a reply, even if someone returns the whole row by mistake.
Try it now
Choosing the status code is part of designing an API: clients decide what to do from it.
Learn it properly
APIs with FastAPI · Typed routes, pydantic models, automatic validation and docs, tested with httpx. About 45 minutes.
Other terms from the same lesson
- pydantic: A Python library that checks data against a class with typed fields, converting values where it can and listing every problem it finds.
Never trained an AI?
Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account.