Coverage for docs_src/dependencies/tutorial012.py: 100%
15 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from fastapi import Depends, FastAPI, Header, HTTPException 1abcde
4async def verify_token(x_token: str = Header()): 1abcde
5 if x_token != "fake-super-secret-token": 1abcde
6 raise HTTPException(status_code=400, detail="X-Token header invalid") 1abcde
9async def verify_key(x_key: str = Header()): 1abcde
10 if x_key != "fake-super-secret-key": 1abcde
11 raise HTTPException(status_code=400, detail="X-Key header invalid") 1abcde
12 return x_key 1abcde
15app = FastAPI(dependencies=[Depends(verify_token), Depends(verify_key)]) 1abcde
18@app.get("/items/") 1abcde
19async def read_items(): 1abcde
20 return [{"item": "Portal Gun"}, {"item": "Plumbus"}] 1abcde
23@app.get("/users/") 1abcde
24async def read_users(): 1abcde
25 return [{"username": "Rick"}, {"username": "Morty"}] 1abcde