From: Sebastián Ramírez Date: Sun, 25 Aug 2024 00:01:04 +0000 (-0500) Subject: 📝 Clarify `response_class` parameter, validations, and returning a response directly... X-Git-Tag: 0.112.3~58 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c692176d4288e8b8f6f404c7c15aaab74083a6e1;p=thirdparty%2Ffastapi%2Ffastapi.git 📝 Clarify `response_class` parameter, validations, and returning a response directly (#12067) --- diff --git a/docs/en/docs/advanced/custom-response.md b/docs/en/docs/advanced/custom-response.md index 8a6555dba1..79f7558153 100644 --- a/docs/en/docs/advanced/custom-response.md +++ b/docs/en/docs/advanced/custom-response.md @@ -4,9 +4,9 @@ By default, **FastAPI** will return the responses using `JSONResponse`. You can override it by returning a `Response` directly as seen in [Return a Response directly](response-directly.md){.internal-link target=_blank}. -But if you return a `Response` directly, the data won't be automatically converted, and the documentation won't be automatically generated (for example, including the specific "media type", in the HTTP header `Content-Type` as part of the generated OpenAPI). +But if you return a `Response` directly (or any subclass, like `JSONResponse`), the data won't be automatically converted (even if you declare a `response_model`), and the documentation won't be automatically generated (for example, including the specific "media type", in the HTTP header `Content-Type` as part of the generated OpenAPI). -But you can also declare the `Response` that you want to be used, in the *path operation decorator*. +But you can also declare the `Response` that you want to be used (e.g. any `Response` subclass), in the *path operation decorator* using the `response_class` parameter. The contents that you return from your *path operation function* will be put inside of that `Response`.