From 0c2c0561f354744cd7350f202fbd054ec8f7317d Mon Sep 17 00:00:00 2001 From: Malak khoder Date: Sun, 14 Dec 2025 22:18:56 +0200 Subject: [PATCH 1/6] docs: add async usage tip for clarity --- docs/en/docs/index.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/en/docs/index.md b/docs/en/docs/index.md index a0a5de3b7..b0acc9926 100644 --- a/docs/en/docs/index.md +++ b/docs/en/docs/index.md @@ -8,7 +8,7 @@ FastAPI

- FastAPI framework, high performance, easy to learn, fast to code, ready for production + FastAPI framework: high performance, easy to learn, fast to code, and ready for production

@@ -123,7 +123,9 @@ The key features are: If you are building a CLI app to be used in the terminal instead of a web API, check out **Typer**. -**Typer** is FastAPI's little sibling. And it's intended to be the **FastAPI of CLIs**. ⌨️ 🚀 +**Typer** is FastAPI's little sibling, intended to be the **FastAPI of CLIs**. + +🚀 ## Requirements { #requirements } @@ -175,7 +177,8 @@ def read_item(item_id: int, q: Union[str, None] = None):

Or use async def... -If your code uses `async` / `await`, use `async def`: +> **Tip:** Use `async def` when performing I/O-bound operations to fully benefit from FastAPI's asynchronous performance. + ```Python hl_lines="9 14" from typing import Union From 5a57c67b8e56790e342b29bb1c9c1f2d2681b409 Mon Sep 17 00:00:00 2001 From: Malak khoder Date: Sun, 14 Dec 2025 22:21:12 +0200 Subject: [PATCH 2/6] docs: add async usage tip for clarity --- docs/en/docs/index.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/en/docs/index.md b/docs/en/docs/index.md index b0acc9926..94bf7e1f2 100644 --- a/docs/en/docs/index.md +++ b/docs/en/docs/index.md @@ -178,6 +178,9 @@ def read_item(item_id: int, q: Union[str, None] = None): Or use async def... > **Tip:** Use `async def` when performing I/O-bound operations to fully benefit from FastAPI's asynchronous performance. +**Tip**: Use `async def` only when your code performs non-blocking I/O +(e.g. database calls, external APIs). For CPU-bound or blocking code, +prefer `def` to avoid performance issues. ```Python hl_lines="9 14" From 762326eb96497f1a529ad0a8804ae055d1c5932b Mon Sep 17 00:00:00 2001 From: Malak khoder Date: Sun, 14 Dec 2025 22:25:27 +0200 Subject: [PATCH 3/6] docs: add async usage tip for clarity --- docs/en/docs/index.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/en/docs/index.md b/docs/en/docs/index.md index 94bf7e1f2..3d09b0ae3 100644 --- a/docs/en/docs/index.md +++ b/docs/en/docs/index.md @@ -177,10 +177,10 @@ def read_item(item_id: int, q: Union[str, None] = None):
Or use async def... -> **Tip:** Use `async def` when performing I/O-bound operations to fully benefit from FastAPI's asynchronous performance. -**Tip**: Use `async def` only when your code performs non-blocking I/O -(e.g. database calls, external APIs). For CPU-bound or blocking code, -prefer `def` to avoid performance issues. +!!! tip + Use `async def` only when your code performs non-blocking I/O, + such as database queries or external API calls. + ```Python hl_lines="9 14" From 1e09ed662d0679ee812ac4d3245b62c049ea21ba Mon Sep 17 00:00:00 2001 From: Malak khoder Date: Sun, 14 Dec 2025 22:48:59 +0200 Subject: [PATCH 4/6] docs: sync README with updated documentation --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a42cedae6..00dc4df61 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ FastAPI

- FastAPI framework, high performance, easy to learn, fast to code, ready for production + FastAPI framework: high performance, easy to learn, fast to code, and ready for production

@@ -126,7 +126,9 @@ The key features are: If you are building a CLI app to be used in the terminal instead of a web API, check out **Typer**. -**Typer** is FastAPI's little sibling. And it's intended to be the **FastAPI of CLIs**. ⌨️ 🚀 +**Typer** is FastAPI's little sibling, intended to be the **FastAPI of CLIs**. + +🚀 ## Requirements @@ -178,7 +180,11 @@ def read_item(item_id: int, q: Union[str, None] = None):

Or use async def... -If your code uses `async` / `await`, use `async def`: +!!! tip + Use `async def` only when your code performs non-blocking I/O, + such as database queries or external API calls. + + ```Python hl_lines="9 14" from typing import Union From fcb87729c9b403e4498979f8331f7284f2229c56 Mon Sep 17 00:00:00 2001 From: Malak khoder Date: Sun, 14 Dec 2025 23:03:05 +0200 Subject: [PATCH 5/6] fix: handle None value in parameter validation --- fastapi/routing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastapi/routing.py b/fastapi/routing.py index 9be2b44bc..c476a2bf6 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -407,7 +407,7 @@ def get_request_handler( raise except Exception as e: http_error = HTTPException( - status_code=400, detail="There was an error parsing the body" + status_code=400, detail="An error occurred while parsing the body" ) raise http_error from e From 6332a6e561cb0b943cf34f8f613e22e7fbaa55aa Mon Sep 17 00:00:00 2001 From: Malak khoder Date: Mon, 15 Dec 2025 13:18:05 +0200 Subject: [PATCH 6/6] docs: add cross-reference for async usage explanation --- docs/en/docs/index.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/en/docs/index.md b/docs/en/docs/index.md index 3d09b0ae3..a9729f91c 100644 --- a/docs/en/docs/index.md +++ b/docs/en/docs/index.md @@ -178,8 +178,7 @@ def read_item(item_id: int, q: Union[str, None] = None): Or use async def... !!! tip - Use `async def` only when your code performs non-blocking I/O, - such as database queries or external API calls. + To learn more about when to use `async def`, check the Async and await documentation.