Routing is an essential part of building a web application. Routing in FastAPI is flexible and hassle-free. Routing is the process of handling HTTP requests sent from a client to the server. HTTP requests are sent to defined routes, which have defined handlers for processing the requests and responding. These handlers are called route handlers.
By the end of this chapter, you will know how to create routes using the APIRouter instance and connect to the main FastAPI application. You will also learn what models are and how to use them to validate request bodies. You will also learn what path and query parameters are and how to use them in your FastAPI application. The knowledge of routing in FastAPI is essential in building small- and large-scale applications.
In this chapter, we’ll be covering the following topics:
- Routing in FastAPI
- Validation using Pydantic models
- Path and query parameters