Documenting your API with Swagger and Redoc
FastAPI automatically generates documentation for your API using Swagger UI and Redoc, when spinning the server.
This documentation is derived from your route functions and Pydantic models, making it incredibly beneficial for both development and consumption by frontend teams or API consumers.
In this recipe, we will see how to customize the documentation’s specific needs.
Getting ready…
By default, FastAPI provides two documentation interfaces:
- Swagger UI: Accessible at
/docs
endpoint (e.g.,http://127.0.0.1:8000/docs
) - Redoc: Accessible at
/redoc
endpoint (e.g.,http://127.0.0.1:8000/redoc
)
These interfaces offer dynamic documentation where users can see and test the API endpoints and their details. However, both pieces of documentation can be modified.
How to do it...
FastAPI allows the customization of Swagger UI. You can add metadata, customize the look, and add additional documentation...