Building response models
We established the purpose of response models at the beginning of this chapter. You also learned how to build models in the previous chapter using Pydantic. Response models are also built on Pydantic but serve a different purpose.
In the definition of route paths, we have the following, for example:
@app.get("/todo") async def retrieve_todo() -> dict: return { "todos": todo_list }
The route returns a list of to-dos present in the database. Here’s some example output:
{ "todos": [ { "id": 1, "item": "Example schema 1!" }, { "id": 2, "item"...