Files
fastapi/docs/em/docs/tutorial/middleware.md
T
Marcelo Trylesinskiandpre-commit-ci[bot] dde7bd1ceb 📝 Replace starlette.io by starlette.dev and uvicorn.org by uvicorn.dev (#14176)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-10-11 17:48:49 +00:00

2.4 KiB
Raw Blame History

🛠️

👆 💪 🚮 🛠️ FastAPI 🈸.

"🛠️" 🔢 👈 👷 ⏮️ 🔠 📨 ⏭ ⚫️ 🛠️ 🙆 🎯 ➡ 🛠️. & ⏮️ 🔠 📨 ⏭ 🛬 ⚫️.

  • ⚫️ ✊ 🔠 📨 👈 👟 👆 🈸.
  • ⚫️ 💪 ⤴️ 🕳 👈 📨 ⚖️ 🏃 🙆 💪 📟.
  • ⤴️ ⚫️ 🚶‍♀️ 📨 🛠️ 🎂 🈸 ( ➡ 🛠️).
  • ⚫️ ⤴️ ✊ 📨 🏗 🈸 ( ➡ 🛠️).
  • ⚫️ 💪 🕳 👈 📨 ⚖️ 🏃 🙆 💪 📟.
  • ⤴️ ⚫️ 📨 📨.

/// note | 📡 ℹ

🚥 👆 ✔️ 🔗 ⏮️ yield, 🚪 📟 🔜 🏃 ⏮️ 🛠️.

🚥 📤 🙆 🖥 📋 (📄 ⏪), 👫 🔜 🏃 ⏮️ 🌐 🛠️.

///

✍ 🛠️

✍ 🛠️ 👆 ⚙️ 👨‍🎨 @app.middleware("http") 🔛 🔝 🔢.

🛠️ 🔢 📨:

  • request.
  • 🔢 call_next 👈 🔜 📨 request 🔢.
    • 👉 🔢 🔜 🚶‍♀️ request 🔗 ➡ 🛠️.
    • ⤴️ ⚫️ 📨 response 🏗 🔗 ➡ 🛠️.
  • 👆 💪 ⤴️ 🔀 🌅 response ⏭ 🛬 ⚫️.

{* ../../docs_src/middleware/tutorial001.py hl[8:9,11,14] *}

/// tip

✔️ 🤯 👈 🛃 © 🎚 💪 🚮 ⚙️ '✖-' 🔡.

✋️ 🚥 👆 ✔️ 🛃 🎚 👈 👆 💚 👩‍💻 🖥 💪 👀, 👆 💪 🚮 👫 👆 ⚜ 📳 (⚜ (✖️-🇨🇳 ℹ 🤝){.internal-link target=_blank}) ⚙️ 🔢 expose_headers 📄 💃 ⚜ 🩺.

///

/// note | 📡 ℹ

👆 💪 ⚙️ from starlette.requests import Request.

FastAPI 🚚 ⚫️ 🏪 👆, 👩‍💻. ✋️ ⚫️ 👟 🔗 ⚪️➡️ 💃.

///

⏭ & ⏮️ response

👆 💪 🚮 📟 🏃 ⏮️ request, ⏭ 🙆 ➡ 🛠️ 📨 ⚫️.

& ⏮️ response 🏗, ⏭ 🛬 ⚫️.

🖼, 👆 💪 🚮 🛃 🎚 X-Process-Time ⚗ 🕰 🥈 👈 ⚫️ ✊ 🛠️ 📨 & 🏗 📨:

{* ../../docs_src/middleware/tutorial001.py hl[10,12:13] *}

🎏 🛠️

👆 💪 ⏪ ✍ 🌖 🔃 🎏 🛠️ 🏧 👩‍💻 🦮: 🏧 🛠️{.internal-link target=_blank}.

👆 🔜 ✍ 🔃 ❔ 🍵 ⚜ ⏮️ 🛠️ ⏭ 📄.