🎚 🔢¶
👆 💪 🔬 🎚 🔢 🎏 🌌 👆 🔬 Query
, Path
& Cookie
🔢.
🗄 Header
¶
🥇 🗄 Header
:
from typing import Union
from fastapi import FastAPI, Header
app = FastAPI()
@app.get("/items/")
async def read_items(user_agent: Union[str, None] = Header(default=None)):
return {"User-Agent": user_agent}
from fastapi import FastAPI, Header
app = FastAPI()
@app.get("/items/")
async def read_items(user_agent: str | None = Header(default=None)):
return {"User-Agent": user_agent}
📣 Header
🔢¶
⤴️ 📣 🎚 🔢 ⚙️ 🎏 📊 ⏮️ Path
, Query
& Cookie
.
🥇 💲 🔢 💲, 👆 💪 🚶♀️ 🌐 ➕ 🔬 ⚖️ ✍ 🔢:
from typing import Union
from fastapi import FastAPI, Header
app = FastAPI()
@app.get("/items/")
async def read_items(user_agent: Union[str, None] = Header(default=None)):
return {"User-Agent": user_agent}
from fastapi import FastAPI, Header
app = FastAPI()
@app.get("/items/")
async def read_items(user_agent: str | None = Header(default=None)):
return {"User-Agent": user_agent}
📡 ℹ
Header
"👭" 🎓 Path
, Query
& Cookie
. ⚫️ 😖 ⚪️➡️ 🎏 ⚠ Param
🎓.
✋️ 💭 👈 🕐❔ 👆 🗄 Query
, Path
, Header
, & 🎏 ⚪️➡️ fastapi
, 👈 🤙 🔢 👈 📨 🎁 🎓.
Info
📣 🎚, 👆 💪 ⚙️ Header
, ↩️ ⏪ 🔢 🔜 🔬 🔢 🔢.
🏧 🛠️¶
Header
✔️ 🐥 ➕ 🛠️ 🔛 🔝 ⚫️❔ Path
, Query
& Cookie
🚚.
🌅 🐩 🎚 🎏 "🔠" 🦹, 💭 "➖ 🔣" (-
).
✋️ 🔢 💖 user-agent
❌ 🐍.
, 🔢, Header
🔜 🗜 🔢 📛 🦹 ⚪️➡️ 🎦 (_
) 🔠 (-
) ⚗ & 📄 🎚.
, 🇺🇸🔍 🎚 💼-😛,, 👆 💪 📣 👫 ⏮️ 🐩 🐍 👗 (💭 "🔡").
, 👆 💪 ⚙️ user_agent
👆 🛎 🔜 🐍 📟, ↩️ 💆♂ 🎯 🥇 🔤 User_Agent
⚖️ 🕳 🎏.
🚥 🤔 👆 💪 ❎ 🏧 🛠️ 🎦 🔠, ⚒ 🔢 convert_underscores
Header
False
:
from typing import Union
from fastapi import FastAPI, Header
app = FastAPI()
@app.get("/items/")
async def read_items(
strange_header: Union[str, None] = Header(default=None, convert_underscores=False),
):
return {"strange_header": strange_header}
from fastapi import FastAPI, Header
app = FastAPI()
@app.get("/items/")
async def read_items(
strange_header: str | None = Header(default=None, convert_underscores=False),
):
return {"strange_header": strange_header}
Warning
⏭ ⚒ convert_underscores
False
, 🐻 🤯 👈 🇺🇸🔍 🗳 & 💽 / ⚙️ 🎚 ⏮️ 🎦.
❎ 🎚¶
⚫️ 💪 📨 ❎ 🎚. 👈 ⛓, 🎏 🎚 ⏮️ 💗 💲.
👆 💪 🔬 👈 💼 ⚙️ 📇 🆎 📄.
👆 🔜 📨 🌐 💲 ⚪️➡️ ❎ 🎚 🐍 list
.
🖼, 📣 🎚 X-Token
👈 💪 😑 🌅 🌘 🕐, 👆 💪 ✍:
from typing import List, Union
from fastapi import FastAPI, Header
app = FastAPI()
@app.get("/items/")
async def read_items(x_token: Union[List[str], None] = Header(default=None)):
return {"X-Token values": x_token}
from typing import Union
from fastapi import FastAPI, Header
app = FastAPI()
@app.get("/items/")
async def read_items(x_token: Union[list[str], None] = Header(default=None)):
return {"X-Token values": x_token}
from fastapi import FastAPI, Header
app = FastAPI()
@app.get("/items/")
async def read_items(x_token: list[str] | None = Header(default=None)):
return {"X-Token values": x_token}
🚥 👆 🔗 ⏮️ 👈 ➡ 🛠️ 📨 2️⃣ 🇺🇸🔍 🎚 💖:
X-Token: foo
X-Token: bar
📨 🔜 💖:
{
"X-Token values": [
"bar",
"foo"
]
}
🌃¶
📣 🎚 ⏮️ Header
, ⚙️ 🎏 ⚠ ⚓ Query
, Path
& Cookie
.
& 🚫 😟 🔃 🎦 👆 🔢, FastAPI 🔜 ✊ 💅 🏭 👫.