快速API 0.68.0
Python 3.8
from fastapi import Depends, FastAPI, Header, HTTPException
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_key)])
@app.get("/items/")
async def read_items():
return [{"item": "Portal Gun"}, {"item": "Plumbus"}]
Run Code Online (Sandbox Code Playgroud)
这是来自FastAPI文档的示例(省略部分代码)
有什么办法可以进去x_key吗read_items()
fastapi ×1