FastAPI系列:路由配置多个http请求方法

一个路由配置多个http请求方法

app = FastAPI(routes=None)

# 方式一:app.api_route()
@app.api_route(path='/index', methods=['GET','POST'])
async def index():
    return {'msg':"index"}

# 方式二:app.add_api_route()
app = FastAPI(routes=None)
async def index():
    return JSONResponse({'msg':"index"})
app.add_api_route(path='/index', endpoint='index', methods=['GET','POST'])
posted @ 2024-02-28 16:48  我在路上回头看  阅读(154)  评论(0编辑  收藏  举报