mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-28 08:40:21 -05:00
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
67 lines
2.4 KiB
Markdown
67 lines
2.4 KiB
Markdown
# 🛠️
|
||
|
||
👆 💪 🚮 🛠️ **FastAPI** 🈸.
|
||
|
||
"🛠️" 🔢 👈 👷 ⏮️ 🔠 **📨** ⏭ ⚫️ 🛠️ 🙆 🎯 *➡ 🛠️*. & ⏮️ 🔠 **📨** ⏭ 🛬 ⚫️.
|
||
|
||
* ⚫️ ✊ 🔠 **📨** 👈 👟 👆 🈸.
|
||
* ⚫️ 💪 ⤴️ 🕳 👈 **📨** ⚖️ 🏃 🙆 💪 📟.
|
||
* ⤴️ ⚫️ 🚶♀️ **📨** 🛠️ 🎂 🈸 ( *➡ 🛠️*).
|
||
* ⚫️ ⤴️ ✊ **📨** 🏗 🈸 ( *➡ 🛠️*).
|
||
* ⚫️ 💪 🕳 👈 **📨** ⚖️ 🏃 🙆 💪 📟.
|
||
* ⤴️ ⚫️ 📨 **📨**.
|
||
|
||
/// note | 📡 ℹ
|
||
|
||
🚥 👆 ✔️ 🔗 ⏮️ `yield`, 🚪 📟 🔜 🏃 *⏮️* 🛠️.
|
||
|
||
🚥 📤 🙆 🖥 📋 (📄 ⏪), 👫 🔜 🏃 *⏮️* 🌐 🛠️.
|
||
|
||
///
|
||
|
||
## ✍ 🛠️
|
||
|
||
✍ 🛠️ 👆 ⚙️ 👨🎨 `@app.middleware("http")` 🔛 🔝 🔢.
|
||
|
||
🛠️ 🔢 📨:
|
||
|
||
* `request`.
|
||
* 🔢 `call_next` 👈 🔜 📨 `request` 🔢.
|
||
* 👉 🔢 🔜 🚶♀️ `request` 🔗 *➡ 🛠️*.
|
||
* ⤴️ ⚫️ 📨 `response` 🏗 🔗 *➡ 🛠️*.
|
||
* 👆 💪 ⤴️ 🔀 🌅 `response` ⏭ 🛬 ⚫️.
|
||
|
||
{* ../../docs_src/middleware/tutorial001.py hl[8:9,11,14] *}
|
||
|
||
/// tip
|
||
|
||
✔️ 🤯 👈 🛃 © 🎚 💪 🚮 <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers" class="external-link" target="_blank">⚙️ '✖-' 🔡</a>.
|
||
|
||
✋️ 🚥 👆 ✔️ 🛃 🎚 👈 👆 💚 👩💻 🖥 💪 👀, 👆 💪 🚮 👫 👆 ⚜ 📳 ([⚜ (✖️-🇨🇳 ℹ 🤝)](cors.md){.internal-link target=_blank}) ⚙️ 🔢 `expose_headers` 📄 <a href="https://www.starlette.dev/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 hl[10,12:13] *}
|
||
|
||
## 🎏 🛠️
|
||
|
||
👆 💪 ⏪ ✍ 🌖 🔃 🎏 🛠️ [🏧 👩💻 🦮: 🏧 🛠️](../advanced/middleware.md){.internal-link target=_blank}.
|
||
|
||
👆 🔜 ✍ 🔃 ❔ 🍵 <abbr title="Cross-Origin Resource Sharing">⚜</abbr> ⏮️ 🛠️ ⏭ 📄.
|