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

16 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 

4 

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

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

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

8 

9 

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

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

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

13 return x_key 1abcde

14 

15 

16app = FastAPI(dependencies=[Depends(verify_token), Depends(verify_key)]) 1abcde

17 

18 

19@app.get("/items/") 1abcde

20async def read_items(): 1abcde

21 return [{"item": "Portal Gun"}, {"item": "Plumbus"}] 1abcde

22 

23 

24@app.get("/users/") 1abcde

25async def read_users(): 1abcde

26 return [{"username": "Rick"}, {"username": "Morty"}] 1abcde