Python fastapi.Header() Examples

The following are 12 code examples of fastapi.Header(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module fastapi , or try the search function .
Example #1
Source File: tutorial003.py    From fastapi with MIT License 6 votes vote down vote up
def read_items(x_token: Optional[List[str]] = Header(None)):
    return {"X-Token values": x_token} 
Example #2
Source File: start.py    From BMW-TensorFlow-Inference-API-CPU with Apache License 2.0 5 votes vote down vote up
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()}) 
Example #3
Source File: test_repeated_dependency_schema.py    From fastapi with MIT License 5 votes vote down vote up
def get_header(*, someheader: str = Header(...)):
    return someheader 
Example #4
Source File: main_b.py    From fastapi with MIT License 5 votes vote down vote up
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] 
Example #5
Source File: main_b.py    From fastapi with MIT License 5 votes vote down vote up
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 
Example #6
Source File: main.py    From fastapi with MIT License 5 votes vote down vote up
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") 
Example #7
Source File: tutorial002.py    From fastapi with MIT License 5 votes vote down vote up
def read_items(
    strange_header: Optional[str] = Header(None, convert_underscores=False)
):
    return {"strange_header": strange_header} 
Example #8
Source File: tutorial006.py    From fastapi with MIT License 5 votes vote down vote up
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 
Example #9
Source File: start.py    From BMW-TensorFlow-Training-GUI with Apache License 2.0 5 votes vote down vote up
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()}) 
Example #10
Source File: start.py    From BMW-YOLOv3-Inference-API-GPU with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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()}) 
Example #11
Source File: start.py    From BMW-TensorFlow-Inference-API-GPU with Apache License 2.0 5 votes vote down vote up
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()}) 
Example #12
Source File: tutorial006.py    From fastapi with MIT License 4 votes vote down vote up
def verify_token(x_token: str = Header(...)):
    if x_token != "fake-super-secret-token":
        raise HTTPException(status_code=400, detail="X-Token header invalid")