GitHub

API reference for HttpApi.

An API of the groups G (group classes), by identifier.

Attributes

AttributeTypeDescription
identifierstr
groupsMapping[str, AnyGroup] = field(default_factory=(dict[str, AnyGroup]))
annotationsContext[Any] = field(default_factory=(Context.empty))

Functions

__init__

__init__(identifier, groups=dict[str, AnyGroup](), annotations=Context.empty()) -> None
ParameterTypeDescription
identifierstr
groupsMapping[str, AnyGroup] = dict[str, AnyGroup]()
annotationsContext[Any] = Context.empty()

make

make(identifier) -> HttpApi[Never]
ParameterTypeDescription
identifierstr

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).

ParameterTypeDescription
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.

ParameterTypeDescription
apiHttpApi[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) -> Self

This API with every endpoint under prefix.

ParameterTypeDescription
prefixstr

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) -> Self

This API with every endpoint wrapped by middleware. Only the run time changes: the handlers and clients are typed by their groups' middleware.

ParameterTypeDescription
middlewareAnyMiddleware

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
ParameterTypeDescription
tagTagLike[S, T]
valueS

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
ParameterTypeDescription
annotationsContext[Any]

Returns Self

def annotate_merge(self, annotations: Context[Any]) -> Self:
    return replace(self, annotations=self.annotations.merge(annotations))

pipe

pipe[B](f) -> B
ParameterTypeDescription
fCallable[[Self], B]

Returns B

def pipe[B](self, f: Callable[[Self], B], /) -> B:
    return f(self)