You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2.4 KiB

🛠️

👆 💪 🚮 🛠️ FastAPI 🈸.

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

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

!!! note "📡 ℹ" 🚥 👆 ✔️ 🔗 ⏮️ yield, 🚪 📟 🔜 🏃 ⏮️ 🛠️.

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

🛠️

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

🛠️ 🔢 📨:

  • request.
  • 🔢 call_next 👈 🔜 📨 request 🔢.
    • 👉 🔢 🔜 🚶‍♀️ request 🔗 🛠️.
    • ⤴️ 📨 response 🏗 🔗 🛠️.
  • 👆 💪 ⤴️ 🔀 🌅 response🛬 ️.
{!../../../docs_src/middleware/tutorial001.py!}

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

✋️ 🚥 👆 ✔️ 🛃 🎚 👈 👆 💚 👩‍💻 🖥 💪 👀, 👆 💪 🚮 👫 👆 ⚜ 📳 ([⚜ (✖️-🇨🇳 ℹ 🤝)](cors.md){.internal-link target=_blank}) ⚙️ 🔢 `expose_headers` 📄 <a href="https://www.starlette.io/middleware/#corsmiddleware" class="external-link" target="_blank">💃 ⚜ 🩺</a>.

!!! note "📡 ℹ" 👆 💪 ⚙️ from starlette.requests import Request.

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

⏭ & ⏮️ response

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

& ⏮️ response 🏗, ⏭ 🛬 ️.

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

{!../../../docs_src/middleware/tutorial001.py!}

🎏 🛠️

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

👆 🔜🔃 🍵 ⏮️ 🛠️📄.