An API of the groups G (group classes), by identifier.
Attributes#
| Attribute | Type | Description |
|---|---|---|
identifier | str | |
groups | Mapping[str, AnyGroup] = field(default_factory=(dict[str, AnyGroup])) | |
annotations | Context[Any] = field(default_factory=(Context.empty)) |
Functions#
__init__#
__init__(identifier, groups=dict[str, AnyGroup](), annotations=Context.empty()) -> None| Parameter | Type | Description |
|---|---|---|
identifier | str | |
groups | Mapping[str, AnyGroup] = dict[str, AnyGroup]() | |
annotations | Context[Any] = Context.empty() |
make#
make(identifier) -> HttpApi[Never]| Parameter | Type | Description |
|---|---|---|
identifier | str |
Returns HttpApi[Never]
@staticmethod
def make(identifier: str) -> HttpApi[Never]:
return HttpApi(identifier)add#
add[G1: HttpApiGroup[Any]](g1: type[G1], /) -> HttpApi[G_co | G1]
add[G1: HttpApiGroup[Any], G2: HttpApiGroup[Any]](g1: type[G1], g2: type[G2], /) -> HttpApi[G_co | G1 | G2]
add[G1: HttpApiGroup[Any], G2: HttpApiGroup[Any], G3: HttpApiGroup[Any]](g1: type[G1], g2: type[G2], g3: type[G3], /) -> HttpApi[G_co | G1 | G2 | G3]This API with more groups (a group replaces one with its identifier).
| Parameter | Type | Description |
|---|---|---|
groups | = () |
@overload
def add[G1: HttpApiGroup[Any]](self, g1: type[G1], /) -> HttpApi[G_co | G1]: ...
@overload
def add[G1: HttpApiGroup[Any], G2: HttpApiGroup[Any]](
self, g1: type[G1], g2: type[G2], /
) -> HttpApi[G_co | G1 | G2]: ...
@overload
def add[G1: HttpApiGroup[Any], G2: HttpApiGroup[Any], G3: HttpApiGroup[Any]](
self, g1: type[G1], g2: type[G2], g3: type[G3], /
) -> HttpApi[G_co | G1 | G2 | G3]: ...
def add(self, *groups: AnyGroup) -> HttpApi[Any]:
"""This API with more groups (a group replaces one with its
identifier)."""
added = dict(self.groups)
for group in groups:
added[group.identifier] = group
return replace(self, groups=added)add_http_api#
add_http_api[G2](api) -> HttpApi[G_co | G2]This API with the groups of api, which keep its annotations
under their own.
| Parameter | Type | Description |
|---|---|---|
api | HttpApi[G2] |
Returns HttpApi[G_co | G2]
def add_http_api[G2](self, api: HttpApi[G2], /) -> HttpApi[G_co | G2]:
"""This API with the groups of ``api``, which keep its annotations
under their own."""
added: dict[str, AnyGroup] = dict(self.groups)
for key, group in api.groups.items():
added[key] = group.annotate_merge(api.annotations.merge(group.annotations))
return HttpApi(self.identifier, added, self.annotations)prefix#
prefix(prefix) -> SelfThis API with every endpoint under prefix.
| Parameter | Type | Description |
|---|---|---|
prefix | str |
Returns Self
def prefix(self, prefix: str) -> Self:
"""This API with every endpoint under ``prefix``."""
return replace(self, groups={k: g.prefix(prefix) for k, g in self.groups.items()})middleware#
middleware(middleware) -> SelfThis API with every endpoint wrapped by middleware. Only the
run time changes: the handlers and clients are typed by their
groups' middleware.
| Parameter | Type | Description |
|---|---|---|
middleware | AnyMiddleware |
Returns Self
def middleware(self, middleware: AnyMiddleware) -> Self:
"""This API with every endpoint wrapped by ``middleware``. Only the
run time changes: the handlers and clients are typed by their
groups' middleware."""
return replace(self, groups={k: g.middleware(middleware) for k, g in self.groups.items()})annotate#
annotate[S, T](tag, value) -> Self| Parameter | Type | Description |
|---|---|---|
tag | TagLike[S, T] | |
value | S |
Returns Self
def annotate[S, T](self, tag: TagLike[S, T], value: S) -> Self:
return replace(self, annotations=self.annotations.add(tag, value))annotate_merge#
annotate_merge(annotations) -> Self| Parameter | Type | Description |
|---|---|---|
annotations | Context[Any] |
Returns Self
def annotate_merge(self, annotations: Context[Any]) -> Self:
return replace(self, annotations=self.annotations.merge(annotations))pipe#
pipe[B](f) -> B| Parameter | Type | Description |
|---|---|---|
f | Callable[[Self], B] |
Returns B
def pipe[B](self, f: Callable[[Self], B], /) -> B:
return f(self)