Overview - Router prefix and tags
What is it?
In FastAPI, a router prefix is a string added before all paths in a router to group related endpoints under a common URL segment. Tags are labels assigned to routes to organize and describe them in the automatic API documentation. Together, prefixes and tags help structure your API routes clearly and make the documentation easier to understand.
Why it matters
Without router prefixes and tags, your API routes can become messy and hard to manage, especially as your application grows. You would have to repeat common path parts for each route and your documentation would lack clear grouping, making it difficult for users and developers to find and understand endpoints. These features save time, reduce errors, and improve collaboration.
Where it fits
Before learning router prefixes and tags, you should understand basic FastAPI routing and path operations. After mastering prefixes and tags, you can explore advanced API design, dependency injection, and security features to build robust APIs.