Coverage for docs_src/dependencies/tutorial006_an.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from fastapi import Depends, FastAPI, Header, HTTPException 1abcde

2from typing_extensions import Annotated 1abcde

3 

4app = FastAPI() 1abcde

5 

6 

7async def verify_token(x_token: Annotated[str, Header()]): 1abcde

8 if x_token != "fake-super-secret-token": 1abcde

9 raise HTTPException(status_code=400, detail="X-Token header invalid") 1abcde

10 

11 

12async def verify_key(x_key: Annotated[str, Header()]): 1abcde

13 if x_key != "fake-super-secret-key": 1abcde

14 raise HTTPException(status_code=400, detail="X-Key header invalid") 1abcde

15 return x_key 1abcde

16 

17 

18@app.get("/items/", dependencies=[Depends(verify_token), Depends(verify_key)]) 1abcde

19async def read_items(): 1abcde

20 return [{"item": "Foo"}, {"item": "Bar"}] 1abcde