Browse Source

📝 Add "Global Responses" section

pull/13650/head
timonrieger 3 months ago
parent
commit
d695c1e521
Failed to extract signature
  1. 14
      docs/en/docs/advanced/additional-responses.md

14
docs/en/docs/advanced/additional-responses.md

@ -191,6 +191,20 @@ But if you have specified a custom response class with `None` as its media type,
///
## Global Responses
You can also register responses at the application level.
This automatically adds the specified response models to every endpoint, without needing to define them individually.
Use the same syntax as demonstrated above.
```Python
class MyErrorModel(BaseModel):
message: str
code: str
app = FastAPI(responses={"default": {"model": MyErrorModel, "description": "Error response"}})
```
## Combining information
You can also combine response information from multiple places, including the `response_model`, `status_code`, and `responses` parameters.

Loading…
Cancel
Save