➡ 🔢 & 🔢 🔬¶
🎏 🌌 👈 👆 💪 📣 🌅 🔬 & 🗃 🔢 🔢 ⏮️ Query
, 👆 💪 📣 🎏 🆎 🔬 & 🗃 ➡ 🔢 ⏮️ Path
.
🗄 ➡¶
🥇, 🗄 Path
⚪️➡️ fastapi
:
from typing import Union
from fastapi import FastAPI, Path, Query
app = FastAPI()
@app.get("/items/{item_id}")
async def read_items(
item_id: int = Path(title="The ID of the item to get"),
q: Union[str, None] = Query(default=None, alias="item-query"),
):
results = {"item_id": item_id}
if q:
results.update({"q": q})
return results
from fastapi import FastAPI, Path, Query
app = FastAPI()
@app.get("/items/{item_id}")
async def read_items(
item_id: int = Path(title="The ID of the item to get"),
q: str | None = Query(default=None, alias="item-query"),
):
results = {"item_id": item_id}
if q:
results.update({"q": q})
return results
📣 🗃¶
👆 💪 📣 🌐 🎏 🔢 Query
.
🖼, 📣 title
🗃 💲 ➡ 🔢 item_id
👆 💪 🆎:
from typing import Union
from fastapi import FastAPI, Path, Query
app = FastAPI()
@app.get("/items/{item_id}")
async def read_items(
item_id: int = Path(title="The ID of the item to get"),
q: Union[str, None] = Query(default=None, alias="item-query"),
):
results = {"item_id": item_id}
if q:
results.update({"q": q})
return results
from fastapi import FastAPI, Path, Query
app = FastAPI()
@app.get("/items/{item_id}")
async def read_items(
item_id: int = Path(title="The ID of the item to get"),
q: str | None = Query(default=None, alias="item-query"),
):
results = {"item_id": item_id}
if q:
results.update({"q": q})
return results
Note
➡ 🔢 🕧 ✔ ⚫️ ✔️ 🍕 ➡.
, 👆 🔜 📣 ⚫️ ⏮️ ...
™ ⚫️ ✔.
👐, 🚥 👆 📣 ⚫️ ⏮️ None
⚖️ ⚒ 🔢 💲, ⚫️ 🔜 🚫 📉 🕳, ⚫️ 🔜 🕧 🚚.
✔ 🔢 👆 💪¶
➡️ 💬 👈 👆 💚 📣 🔢 🔢 q
✔ str
.
& 👆 🚫 💪 📣 🕳 🙆 👈 🔢, 👆 🚫 🤙 💪 ⚙️ Query
.
✋️ 👆 💪 ⚙️ Path
item_id
➡ 🔢.
🐍 🔜 😭 🚥 👆 🚮 💲 ⏮️ "🔢" ⏭ 💲 👈 🚫 ✔️ "🔢".
✋️ 👆 💪 🏤-✔ 👫, & ✔️ 💲 🍵 🔢 (🔢 🔢 q
) 🥇.
⚫️ 🚫 🤔 FastAPI. ⚫️ 🔜 🔍 🔢 👫 📛, 🆎 & 🔢 📄 (Query
, Path
, ♒️), ⚫️ 🚫 💅 🔃 ✔.
, 👆 💪 📣 👆 🔢:
from fastapi import FastAPI, Path
app = FastAPI()
@app.get("/items/{item_id}")
async def read_items(q: str, item_id: int = Path(title="The ID of the item to get")):
results = {"item_id": item_id}
if q:
results.update({"q": q})
return results
✔ 🔢 👆 💪, 🎱¶
🚥 👆 💚 📣 q
🔢 🔢 🍵 Query
🚫 🙆 🔢 💲, & ➡ 🔢 item_id
⚙️ Path
, & ✔️ 👫 🎏 ✔, 🐍 ✔️ 🐥 🎁 ❕ 👈.
🚶♀️ *
, 🥇 🔢 🔢.
🐍 🏆 🚫 🕳 ⏮️ 👈 *
, ✋️ ⚫️ 🔜 💭 👈 🌐 📄 🔢 🔜 🤙 🇨🇻 ❌ (🔑-💲 👫), 💭 kwargs
. 🚥 👫 🚫 ✔️ 🔢 💲.
from fastapi import FastAPI, Path
app = FastAPI()
@app.get("/items/{item_id}")
async def read_items(*, item_id: int = Path(title="The ID of the item to get"), q: str):
results = {"item_id": item_id}
if q:
results.update({"q": q})
return results
🔢 🔬: 👑 🌘 ⚖️ 🌓¶
⏮️ Query
& Path
(& 🎏 👆 🔜 👀 ⏪) 👆 💪 📣 🔢 ⚛.
📥, ⏮️ ge=1
, item_id
🔜 💪 🔢 🔢 "g
🅾 🌘 ⚖️ e
🅾" 1
.
from fastapi import FastAPI, Path
app = FastAPI()
@app.get("/items/{item_id}")
async def read_items(
*, item_id: int = Path(title="The ID of the item to get", ge=1), q: str
):
results = {"item_id": item_id}
if q:
results.update({"q": q})
return results
🔢 🔬: 🌘 🌘 & 🌘 🌘 ⚖️ 🌓¶
🎏 ✔:
gt
:g
🅾t
👲le
:l
👭 🌘 ⚖️e
🅾
from fastapi import FastAPI, Path
app = FastAPI()
@app.get("/items/{item_id}")
async def read_items(
*,
item_id: int = Path(title="The ID of the item to get", gt=0, le=1000),
q: str,
):
results = {"item_id": item_id}
if q:
results.update({"q": q})
return results
🔢 🔬: 🎈, 🌘 🌘 & 🌘 🌘¶
🔢 🔬 👷 float
💲.
📥 🌐❔ ⚫️ ▶️️ ⚠ 💪 📣 gt
& 🚫 ge
. ⏮️ ⚫️ 👆 💪 🚚, 🖼, 👈 💲 🔜 👑 🌘 0
, 🚥 ⚫️ 🌘 🌘 1
.
, 0.5
🔜 ☑ 💲. ✋️ 0.0
⚖️ 0
🔜 🚫.
& 🎏 lt
.
from fastapi import FastAPI, Path, Query
app = FastAPI()
@app.get("/items/{item_id}")
async def read_items(
*,
item_id: int = Path(title="The ID of the item to get", ge=0, le=1000),
q: str,
size: float = Query(gt=0, lt=10.5),
):
results = {"item_id": item_id}
if q:
results.update({"q": q})
return results
🌃¶
⏮️ Query
, Path
(& 🎏 👆 🚫 👀) 👆 💪 📣 🗃 & 🎻 🔬 🎏 🌌 ⏮️ 🔢 🔢 & 🎻 🔬.
& 👆 💪 📣 🔢 🔬:
gt
:g
🅾t
👲ge
:g
🅾 🌘 ⚖️e
🅾lt
:l
👭t
👲le
:l
👭 🌘 ⚖️e
🅾
Info
Query
, Path
, & 🎏 🎓 👆 🔜 👀 ⏪ 🏿 ⚠ Param
🎓.
🌐 👫 💰 🎏 🔢 🌖 🔬 & 🗃 👆 ✔️ 👀.
📡 ℹ
🕐❔ 👆 🗄 Query
, Path
& 🎏 ⚪️➡️ fastapi
, 👫 🤙 🔢.
👈 🕐❔ 🤙, 📨 👐 🎓 🎏 📛.
, 👆 🗄 Query
, ❔ 🔢. & 🕐❔ 👆 🤙 ⚫️, ⚫️ 📨 👐 🎓 🌟 Query
.
👫 🔢 📤 (↩️ ⚙️ 🎓 🔗) 👈 👆 👨🎨 🚫 ™ ❌ 🔃 👫 🆎.
👈 🌌 👆 💪 ⚙️ 👆 😐 👨🎨 & 🛠️ 🧰 🍵 ✔️ 🚮 🛃 📳 🤷♂ 📚 ❌.