ChildAPI¶
- class deepfos.api.base.ChildAPI(root: deepfos.api.base.RootAPI)¶
固定地址 API 的子路由封装
ChildAPI不能独立使用,通常作为RootAPI的cached_property返回值出现,用来表达 /root/child/… 这类层级式接口结构。示例
from deepfos.api.base import RootAPI, ChildAPI, get from deepfos.lib.decorator import cached_property class DetailAPI(ChildAPI): endpoint = '/detail' @get('/open') def open(self, id_: str): return {'param': {'id': id_}} class ExampleAPI(RootAPI): prefix = staticmethod(lambda: 'http://localhost:8080') @cached_property def detail(self) -> DetailAPI: return DetailAPI(self)
方法
收集当前 API 类暴露的所有相对 endpoint
拼接父 API 与当前子路由的完整基础地址
prefix()resolve_cls(sync, sync_base, async_base[, extra])根据同步/异步模式生成实际可实例化的 API 类
resolve_version_cls(sync, sync_base, async_base)为多版本动态 API 解析指定版本对应的运行期类
属性