Summary
In this chapter, we learned how to use the APIRouter
class and connect routes defined with it to the primary FastAPI instance. We also learned how to create models for our request bodies and add path and query parameters to our path operations. These models serve as extra validation against improper data types supplied to request body fields. We also built a CRUD todo application to put into practice all that we learned in this chapter.
In the next chapter, you will be introduced to response, response modeling, and error handling in FastAPI. You will first be introduced to the concept of responses and how the knowledge of Pydantic models learned in this chapter helps build models for API responses. You will then learn about status codes and how to use them in your response objects and proper error handling.