本文整理匯總了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