# fastapi 路由管理

#### 定义包并编写路由

```python
# routers\zlmedia_hook.py

from fastapi import APIRouter


router = APIRouter(prefix="/zlmedia/hook", tags=["zlmedia_hook"])


@router.get("/")
async def hello():
    return {"code": "0", "message": "success", "data": "hello world"}


```

#### 自动加载路由

```python

# main.py

import routers.zlmedia_hook as zlmedia_hook


# 附件路由
app.include_router(zlmedia_hook.router)

```