From 0e95304392f61b4bd672852d4f4a39ec4300e989 Mon Sep 17 00:00:00 2001 From: Yash Gupta Date: Fri, 9 Jan 2026 16:28:47 +0530 Subject: [PATCH] docs: add notes on dynamic response status codes --- .../en/docs/advanced/response-change-status-code.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/en/docs/advanced/response-change-status-code.md b/docs/en/docs/advanced/response-change-status-code.md index d9708aa62..4a258d8f5 100644 --- a/docs/en/docs/advanced/response-change-status-code.md +++ b/docs/en/docs/advanced/response-change-status-code.md @@ -29,3 +29,16 @@ And if you declared a `response_model`, it will still be used to filter and conv **FastAPI** will use that *temporal* response to extract the status code (also cookies and headers), and will put them in the final response that contains the value you returned, filtered by any `response_model`. You can also declare the `Response` parameter in dependencies, and set the status code in them. But keep in mind that the last one to be set will win. + +## Notes + +The `status_code` can be set dynamically depending on your application logic. + +For example, you might return: + +- `200 OK` when the data already exists +- `201 Created` when new data is created +- `204 No Content` when no response body is needed + +This allows reusing the same path operation while still returning accurate HTTP status codes. +