mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-10-30 20:24:47 +08:00
- docs/dev/plugins.md 改为总览与导航,旧内容拆入 docs/dev/plugins/ - 新增核心概念、配置表单、事件、前端挂载点、命令行、签名与分发、内置插件、示例页 - 每个扩展点一页,侧边栏由页面表生成 - 改正旧文档中下载器配置、hardlink path_map 与补链按钮的过时描述
1.3 KiB
1.3 KiB
REST Routes (api_router)
Adds HTTP endpoints to a plugin. They are often the backend of a frontend component. @provider(points.API_ROUTER, id=...) returns a fastapi.APIRouter.
from fastapi import APIRouter
@provider(points.API_ROUTER, id="api")
def api(self):
router = APIRouter()
@router.get("/stats")
async def stats():
return {"count": await self.ctx.kv.get("count", 0)}
return router
- AB mounts the routes under
/api/v1/plugins/<plugin id>/. The example above isGET /api/v1/plugins/my-plugin/stats. Theidmust be unique only inside the plugin. - All plugin routes require a login. They use the same credentials as the other WebUI endpoints (a session cookie or an API token with
scope=api). A plugin cannot register an anonymous endpoint. A request without a login gets 401. - Routes appear when the plugin is enabled and disappear when it is disabled. No restart is necessary. One plugin can provide several
API_ROUTERitems. AB merges them under the same prefix. - A handler that raises
HTTPExceptionreturns that status code. Any other exception returns 500 and counts toward the breaker. - Plugin routes are not in the OpenAPI document at
/docs. - Reserved paths:
web/(frontend static files),installandcatalog(see Signing and distribution) cannot be route paths.