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

15 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-05-05 00:03 +0000

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

2 

3 

4async def verify_token(x_token: str = Header()): 1abcdef

5 if x_token != "fake-super-secret-token": 1EFstghGHuvijIJwxklKLyzmnMNABopOPCDqr

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

7 

8 

9async def verify_key(x_key: str = Header()): 1abcdef

10 if x_key != "fake-super-secret-key": 1stghuvijwxklyzmnABopCDqr

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

12 return x_key 1ghijklmnopqr

13 

14 

15app = FastAPI(dependencies=[Depends(verify_token), Depends(verify_key)]) 1abcdef

16 

17 

18@app.get("/items/") 1abcdef

19async def read_items(): 1abcdef

20 return [{"item": "Portal Gun"}, {"item": "Plumbus"}] 1gikmoq

21 

22 

23@app.get("/users/") 1abcdef

24async def read_users(): 1abcdef

25 return [{"username": "Rick"}, {"username": "Morty"}] 1hjlnpr