FastAPI系列:全局routes参数的使用
全局routes参数的使用
from fastapi import FastAPI, Request
from fastapi.response import JSONResponse
from fastapi.routing import APIRoute
async def fastapi_index():
return JSONResponse({'index':'fastapi_index'})
async def fastapi_about():
return JSONResponse({'about':'fastapi_about'})
routes = [
# endpoint指定端点,methods指定允许访问的方法
APIRoute(path='/fastapi/index', endpoint=fastapi_index, methods=['GET','POST']),
APIRoute(path='/fastapi/about', endpoint=fastapi_about, methods=['POST'])
]
app = FastAPI(routes=routes)
-------------------------------------------
个性签名:代码过万,键盘敲烂!!!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!