๐ ๐¶
๐ ๐ธ ๐ ๐ช ๐ ๐ฎ ๐ ๐ ๐ธ.
๐ ๐ ๐ ๐ช ๐ฎ dependencies
โก ๐ ๏ธ ๐จโ๐จ, ๐ ๐ช ๐ฎ ๐ซ FastAPI
๐ธ.
๐ ๐ผ, ๐ซ ๐ โ ๐ โก ๐ ๏ธ ๐ธ:
from fastapi import Depends, FastAPI, Header, HTTPException
async def verify_token(x_token: str = Header()):
if x_token != "fake-super-secret-token":
raise HTTPException(status_code=400, detail="X-Token header invalid")
async def verify_key(x_key: str = Header()):
if x_key != "fake-super-secret-key":
raise HTTPException(status_code=400, detail="X-Key header invalid")
return x_key
app = FastAPI(dependencies=[Depends(verify_token), Depends(verify_key)])
@app.get("/items/")
async def read_items():
return [{"item": "Portal Gun"}, {"item": "Plumbus"}]
@app.get("/users/")
async def read_users():
return [{"username": "Rick"}, {"username": "Morty"}]
& ๐ ๐ญ ๐ ๐ โ dependencies
โก ๐ ๏ธ ๐จโ๐จ โ, โ๏ธ ๐ ๐ผ, ๐ โก ๐ ๏ธ ๐ฑ.
๐ ๐ช โก ๐ ๏ธ¶
โช, ๐โ ๐ ๐ โ ๐ ๐ฆ ๐ธ (๐ฆ ๐ธ - ๐ ๐), ๐ฒ โฎ๏ธ ๐ ๐, ๐ ๐ ๐ก โ ๐ฃ ๐ dependencies
๐ข ๐ช โก ๐ ๏ธ.