Coverage for docs_src/dependencies/tutorial006_an_py39.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from typing import Annotated 1abcd
3from fastapi import Depends, FastAPI, Header, HTTPException 1abcd
5app = FastAPI() 1abcd
8async def verify_token(x_token: Annotated[str, Header()]): 1abcd
9 if x_token != "fake-super-secret-token": 1abcd
10 raise HTTPException(status_code=400, detail="X-Token header invalid") 1abcd
13async def verify_key(x_key: Annotated[str, Header()]): 1abcd
14 if x_key != "fake-super-secret-key": 1abcd
15 raise HTTPException(status_code=400, detail="X-Key header invalid") 1abcd
16 return x_key 1abcd
19@app.get("/items/", dependencies=[Depends(verify_token), Depends(verify_key)]) 1abcd
20async def read_items(): 1abcd
21 return [{"item": "Foo"}, {"item": "Bar"}] 1abcd