Coverage for docs_src/dependencies/tutorial012_an_py39.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 1abcd

2from typing_extensions import Annotated 1abcd

3 

4 

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

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

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

8 

9 

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

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

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

13 return x_key 1abcd

14 

15 

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

17 

18 

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

20async def read_items(): 1abcd

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

22 

23 

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

25async def read_users(): 1abcd

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