用@app.get(), @app.post(), 装饰器from fastapi import FastAPI from fastapi.responses import JSONResponse app = FastAPI() @app.get("/items/", responses={ 200: { "description": "Successful Response", "content": { "application/json": { "example": {"item": "Foo"} }, }, }, 201: {"description": "Created"}, 401: {"description": "Unauthorized"}, 404: {"description": "Not Found"}, 500: {"description": "Internal Server Error"}, }) async def read_items(): return JSONResponse(content={"item": "Foo"}, status_code=200)
用@app.get(), @app.post(), 装饰器