本文整理汇总了Python中fastapi.Header方法的典型用法代码示例。如果您正苦于以下问题:Python fastapi.Header方法的具体用法?Python fastapi.Header怎么用?Python fastapi.Header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fastapi
的用法示例。
在下文中一共展示了fastapi.Header方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list_models
# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Header [as 别名]
def list_models(user_agent: str = Header(None)):
"""
Lists all available models.
:param user_agent:
:return: APIResponse
"""
return ApiResponse(data={'models': dl_service.list_models()})
示例2: get_header
# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Header [as 别名]
def get_header(*, someheader: str = Header(...)):
return someheader
示例3: read_main
# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Header [as 别名]
def read_main(item_id: str, x_token: str = Header(...)):
if x_token != fake_secret_token:
raise HTTPException(status_code=400, detail="Invalid X-Token header")
if item_id not in fake_db:
raise HTTPException(status_code=404, detail="Item not found")
return fake_db[item_id]
示例4: create_item
# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Header [as 别名]
def create_item(item: Item, x_token: str = Header(...)):
if x_token != fake_secret_token:
raise HTTPException(status_code=400, detail="Invalid X-Token header")
if item.id in fake_db:
raise HTTPException(status_code=400, detail="Item already exists")
fake_db[item.id] = item
return item
示例5: get_token_header
# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Header [as 别名]
def get_token_header(x_token: str = Header(...)):
if x_token != "fake-super-secret-token":
raise HTTPException(status_code=400, detail="X-Token header invalid")
示例6: read_items
# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Header [as 别名]
def read_items(
strange_header: Optional[str] = Header(None, convert_underscores=False)
):
return {"strange_header": strange_header}
示例7: read_items
# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Header [as 别名]
def read_items(x_token: Optional[List[str]] = Header(None)):
return {"X-Token values": x_token}
示例8: verify_token
# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Header [as 别名]
def verify_token(x_token: str = Header(...)):
if x_token != "fake-super-secret-token":
raise HTTPException(status_code=400, detail="X-Token header invalid")
示例9: verify_key
# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Header [as 别名]
def verify_key(x_key: str = Header(...)):
if x_key != "fake-super-secret-key":
raise HTTPException(status_code=400, detail="X-Key header invalid")
return x_key