全局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)
标签:index,about,methods,FastAPI,fastapi,routes,全局
From: https://www.cnblogs.com/weiweivip666/p/18041008