1.7 路由分发
apps/app01.py
from fastapi import APIRouter
app01 = APIRouter()
@app01.get("/food")
async def shop_food():
return {"shop": "food"}
@app01.get("/bed")
async def shop_food():
return {"shop": "bed"}
apps/app02.py
from fastapi import APIRouter
app02 = APIRouter()
@app02.post("/login")
async def shop_food():
return {"user": "login"}
@app02.get("/reg")
async def shop_food():
return {"user": "reg"}
main.py
import uvicorn
from fastapi import FastAPI
from apps.app01 import app01
from apps.app02 import app02
app = FastAPI()
app.include_router(app01, prefix="/shop", tags=["购物中心接口"])
app.include_router(app02, prefix="/user", tags=["用户中心接口"])
if __name__ == '__main__':
uvicorn.run('main:app', port=5050, reload=True)