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

16 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-04 08:29 +0000

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

2from typing_extensions import Annotated 1abcdefg

3 

4 

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

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

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

8 

9 

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

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

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

13 return x_key 1hijklmnopqrstu

14 

15 

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

17 

18 

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

20async def read_items(): 1abcdefg

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

22 

23 

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

25async def read_users(): 1abcdefg

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