Coverage for docs_src/dependencies/tutorial006.py: 100%
12 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
3app = FastAPI() 1abcde
6async def verify_token(x_token: str = Header()): 1abcde
7 if x_token != "fake-super-secret-token": 1abcde
8 raise HTTPException(status_code=400, detail="X-Token header invalid") 1abcde
11async def verify_key(x_key: str = Header()): 1abcde
12 if x_key != "fake-super-secret-key": 1abcde
13 raise HTTPException(status_code=400, detail="X-Key header invalid") 1abcde
14 return x_key 1abcde
17@app.get("/items/", dependencies=[Depends(verify_token), Depends(verify_key)]) 1abcde
18async def read_items(): 1abcde
19 return [{"item": "Foo"}, {"item": "Bar"}] 1abcde