from fastapi import FastAPI,Path
app = FastAPI()
# Path校验
'''
限制接口输入的数字大小限制 100-1000
限制字符串输入的字符数量 3-8位
'''
@app.get("/number/{num}")
def number(num:int = Path(ge=100,le=1000)):
return {"number":num}
@app.get("/word/{name}")
def word(name:str = Path(min_length=3,max_length=8)):
return {"word":name}
[FastAPI-08]Path校验
发布时间 2023-03-23 16:43:36作者: LeoShi2020