Path 클래스
from fastapi import Path
- path parameter에 대한 설정을 Path 클래스로 할 수 있습니다.
int 제한
- ge: greater than or equal
- gt: greater than
- lt: less than
- le: less than or equal
from typing import Optional,
from fastapi import FastAPI, Path
@app.get("/items/{item_id}")
async def read_item(
item_id: int = Path(..., ge=1),
q: Optional[str] = Query(None, alias="item-query"),
):
results = { "item_id": item_id }
if q:
results.update({"q": q})
return {"item_id": item_id, "q": q}
from typing import Optional,
from fastapi import FastAPI, Path
@app.get("/items/{item_id}")
async def read_item(
item_id: int = Path(..., title="The ID of the item to get"),
q: Optional[str] = Query(None, alias="item-query"),
):
results = { "item_id": item_id }
if q:
results.update({"q": q})
return {"item_id": item_id, "q": q}
연관 페이지
참고 문헌 / 사이트