<ahref="https://platform.sh/try-it-now/?utm_source=fastapi-signup&utm_medium=banner&utm_campaign=FastAPI-signup-June-2023"target="_blank"title="Build, run and scale your apps on a modern, reliable, and secure PaaS."><imgsrc="https://fastapi.tiangolo.com/img/sponsors/platform-sh.png"></a>
<ahref="https://platform.sh/try-it-now/?utm_source=fastapi-signup&utm_medium=banner&utm_campaign=FastAPI-signup-June-2023"target="_blank"title="Build, run and scale your apps on a modern, reliable, and secure PaaS."><imgsrc="https://fastapi.tiangolo.com/img/sponsors/platform-sh.png"></a>
<ahref="https://www.porter.run"target="_blank"title="Deploy FastAPI on AWS with a few clicks"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/porter.png"></a>
<ahref="https://www.porter.run"target="_blank"title="Deploy FastAPI on AWS with a few clicks"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/porter.png"></a>
<ahref="https://bump.sh/fastapi?utm_source=fastapi&utm_medium=referral&utm_campaign=sponsor"target="_blank"title="Automate FastAPI documentation generation with Bump.sh"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/bump-sh.svg"></a>
<ahref="https://bump.sh/fastapi?utm_source=fastapi&utm_medium=referral&utm_campaign=sponsor"target="_blank"title="Automate FastAPI documentation generation with Bump.sh"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/bump-sh.svg"></a>
<ahref="https://github.com/scalar/scalar/?utm_source=fastapi&utm_medium=website&utm_campaign=main-badge"target="_blank"title="Scalar: Beautiful Open-Source API References from Swagger/OpenAPI files"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/scalar.svg"></a>
<ahref="https://github.com/scalar/scalar/?utm_source=fastapi&utm_medium=website&utm_campaign=main-badge"target="_blank"title="Scalar: Beautiful Open-Source API References from Swagger/OpenAPI files"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/scalar.svg"></a>
<ahref="https://www.propelauth.com/?utm_source=fastapi&utm_campaign=1223&utm_medium=mainbadge"target="_blank"title="Auth, user management and more for your B2B product"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/propelauth.png"></a>
<ahref="https://www.propelauth.com/?utm_source=fastapi&utm_campaign=1223&utm_medium=mainbadge"target="_blank"title="Auth, user management and more for your B2B product"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/propelauth.png"></a>
<ahref="https://fine.dev?ref=fastapibadge"target="_blank"title="Fine's AI FastAPI Workflow: Effortlessly Deploy and Integrate FastAPI into Your Project"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/fine.png"></a>
<ahref="https://fine.dev?ref=fastapibadge"target="_blank"title="Fine's AI FastAPI Workflow: Effortlessly Deploy and Integrate FastAPI into Your Project"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/fine.png"></a>
<ahref="https://github.com/deepset-ai/haystack/"target="_blank"title="Build powerful search from composable, open source building blocks"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/haystack-fastapi.svg"></a>
<ahref="https://github.com/deepset-ai/haystack/"target="_blank"title="Build powerful search from composable, open source building blocks"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/haystack-fastapi.svg"></a>
<ahref="https://databento.com/"target="_blank"title="Pay as you go for market data"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/databento.svg"></a>
<ahref="https://databento.com/"target="_blank"title="Pay as you go for market data"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/databento.svg"></a>
<ahref="https://speakeasyapi.dev?utm_source=fastapi+repo&utm_medium=github+sponsorship"target="_blank"title="SDKs for your API | Speakeasy"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/speakeasy.png"></a>
<ahref="https://speakeasy.com?utm_source=fastapi+repo&utm_medium=github+sponsorship"target="_blank"title="SDKs for your API | Speakeasy"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/speakeasy.png"></a>
<ahref="https://www.svix.com/"target="_blank"title="Svix - Webhooks as a service"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/svix.svg"></a>
<ahref="https://www.svix.com/"target="_blank"title="Svix - Webhooks as a service"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/svix.svg"></a>
<ahref="https://www.codacy.com/?utm_source=github&utm_medium=sponsors&utm_id=pioneers"target="_blank"title="Take code reviews from hours to minutes"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/codacy.png"></a>
<ahref="https://www.codacy.com/?utm_source=github&utm_medium=sponsors&utm_id=pioneers"target="_blank"title="Take code reviews from hours to minutes"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/codacy.png"></a>
@ -20,7 +20,7 @@ Einige von diesen ✨ [**sponsern FastAPI**](../help-fastapi.md#den-autor-sponse
Und es zeigt deren wahres Engagement für FastAPI und seine **Community** (Sie), da diese Ihnen nicht nur einen **guten Service** bieten möchten, sondern auch sicherstellen möchten, dass Sie über ein **gutes und gesundes Framework** verfügen, FastAPI. 🙇
Und es zeigt deren wahres Engagement für FastAPI und seine **Community** (Sie), da diese Ihnen nicht nur einen **guten Service** bieten möchten, sondern auch sicherstellen möchten, dass Sie über ein **gutes und gesundes Framework** verfügen, FastAPI. 🙇
Beispielsweise könnten Sie <ahref="https://speakeasyapi.dev/?utm_source=fastapi+repo&utm_medium=github+sponsorship"class="external-link"target="_blank">Speakeasy</a> ausprobieren.
Beispielsweise könnten Sie <ahref="https://speakeasy.com/?utm_source=fastapi+repo&utm_medium=github+sponsorship"class="external-link"target="_blank">Speakeasy</a> ausprobieren.
Es gibt auch mehrere andere Unternehmen, welche ähnliche Dienste anbieten und die Sie online suchen und finden können. 🤓
Es gibt auch mehrere andere Unternehmen, welche ähnliche Dienste anbieten und die Sie online suchen und finden können. 🤓
@ -20,7 +20,7 @@ Some of them also ✨ [**sponsor FastAPI**](../help-fastapi.md#sponsor-the-autho
And it shows their true commitment to FastAPI and its **community** (you), as they not only want to provide you a **good service** but also want to make sure you have a **good and healthy framework**, FastAPI. 🙇
And it shows their true commitment to FastAPI and its **community** (you), as they not only want to provide you a **good service** but also want to make sure you have a **good and healthy framework**, FastAPI. 🙇
For example, you might want to try <ahref="https://speakeasyapi.dev/?utm_source=fastapi+repo&utm_medium=github+sponsorship"class="external-link"target="_blank">Speakeasy</a> and <ahref="https://www.stainlessapi.com/?utm_source=fastapi&utm_medium=referral"class="external-link"target="_blank">Stainless</a>.
For example, you might want to try <ahref="https://speakeasy.com/?utm_source=fastapi+repo&utm_medium=github+sponsorship"class="external-link"target="_blank">Speakeasy</a> and <ahref="https://www.stainlessapi.com/?utm_source=fastapi&utm_medium=referral"class="external-link"target="_blank">Stainless</a>.
There are also several other companies offering similar services that you can search and find online. 🤓
There are also several other companies offering similar services that you can search and find online. 🤓
* 📝 Update Speakeasy URL. PR [#11871](https://github.com/tiangolo/fastapi/pull/11871) by [@ndimares](https://github.com/ndimares).
### Translations
### Translations
* 🌐 Add Portuguese translation for `docs/pt/docs/advanced/response-change-status-code.md`. PR [#11863](https://github.com/tiangolo/fastapi/pull/11863) by [@ceb10n](https://github.com/ceb10n).
* 🌐 Add Portuguese translation for `docs/pt/docs/reference/background.md`. PR [#11849](https://github.com/tiangolo/fastapi/pull/11849) by [@lucasbalieiro](https://github.com/lucasbalieiro).
* 🌐 Add Portuguese translation for `docs/pt/docs/reference/background.md`. PR [#11849](https://github.com/tiangolo/fastapi/pull/11849) by [@lucasbalieiro](https://github.com/lucasbalieiro).
* 🌐 Add Portuguese translation for `docs/pt/docs/tutorial/dependencies/dependencies-with-yield.md`. PR [#11848](https://github.com/tiangolo/fastapi/pull/11848) by [@Joao-Pedro-P-Holanda](https://github.com/Joao-Pedro-P-Holanda).
* 🌐 Add Portuguese translation for `docs/pt/docs/tutorial/dependencies/dependencies-with-yield.md`. PR [#11848](https://github.com/tiangolo/fastapi/pull/11848) by [@Joao-Pedro-P-Holanda](https://github.com/Joao-Pedro-P-Holanda).
* 🌐 Add Portuguese translation for `docs/pt/docs/reference/apirouter.md`. PR [#11843](https://github.com/tiangolo/fastapi/pull/11843) by [@lucasbalieiro](https://github.com/lucasbalieiro).
* 🌐 Add Portuguese translation for `docs/pt/docs/reference/apirouter.md`. PR [#11843](https://github.com/tiangolo/fastapi/pull/11843) by [@lucasbalieiro](https://github.com/lucasbalieiro).
### Internal
### Internal
* 🔧 Update sponsors, remove Reflex. PR [#11875](https://github.com/tiangolo/fastapi/pull/11875) by [@tiangolo](https://github.com/tiangolo).
* 🔧 Update sponsors: remove TalkPython. PR [#11861](https://github.com/tiangolo/fastapi/pull/11861) by [@tiangolo](https://github.com/tiangolo).
* 🔧 Update sponsors: remove TalkPython. PR [#11861](https://github.com/tiangolo/fastapi/pull/11861) by [@tiangolo](https://github.com/tiangolo).
* 🔨 Update docs Termynal scripts to not include line nums for local dev. PR [#11854](https://github.com/tiangolo/fastapi/pull/11854) by [@tiangolo](https://github.com/tiangolo).
* 🔨 Update docs Termynal scripts to not include line nums for local dev. PR [#11854](https://github.com/tiangolo/fastapi/pull/11854) by [@tiangolo](https://github.com/tiangolo).
Você provavelmente leu anteriormente que você pode definir um [Código de Status do Retorno](../tutorial/response-status-code.md){.internal-link target=_blank} padrão.
Porém em alguns casos você precisa retornar um código de status diferente do padrão.
## Caso de uso
Por exemplo, imagine que você deseja retornar um código de status HTTP de "OK" `200` por padrão.
Mas se o dado não existir, você quer criá-lo e retornar um código de status HTTP de "CREATED" `201`.
Mas você ainda quer ser capaz de filtrar e converter o dado que você retornará com um `response_model`.
Para estes casos, você pode utilizar um parâmetro `Response`.
## Use um parâmetro `Response`
Você pode declarar um parâmetro do tipo `Response` em sua *função de operação de rota* (assim como você pode fazer para cookies e headers).
E então você pode definir o `status_code` neste objeto de retorno temporal.
E então você pode retornar qualquer objeto que você precise, como você faria normalmente (um `dict`, um modelo de banco de dados, etc.).
E se você declarar um `response_model`, ele ainda será utilizado para filtrar e converter o objeto que você retornou.
O **FastAPI** utilizará este retorno *temporal* para extrair o código de status (e também cookies e headers), e irá colocá-los no retorno final que contém o valor que você retornou, filtrado por qualquer `response_model`.
Você também pode declarar o parâmetro `Response` nas dependências, e definir o código de status nelas. Mas lembre-se que o último que for definido é o que prevalecerá.