GitHub

HttpApiGroup

API reference for HttpApiGroup.

A group of endpoints wrapped by the middleware M (a middleware class, or a union of them). Leave out MT: it repeats M so that the builder can read both the middleware and what it provides.

Attributes

AttributeTypeDescription
identifierstr
top_levelbool
endpointsMapping[str, AnyEndpoint]
annotationsContext[Any]
origintype[HttpApiGroup[Any]]

The class whose handlers this group's are: itself, or the group it was derived from with prefix, add, ...

Functions

method

method(identifier) -> Any

On a client's group, the client method of the endpoint identifier: for endpoints added with add rather than declared as attributes (which type their methods).

ParameterTypeDescription
identifierstr

Returns Any

def method(self, identifier: str, /) -> Any:
    """On a client's group, the client method of the endpoint
    ``identifier``: for endpoints added with ``add`` rather than
    declared as attributes (which type their methods)."""
    methods: Mapping[str, Any] | None = getattr(self, "_http_api_client", None)
    if methods is None:
        raise TypeError("method() reads a client's group (get_group(client, Group))")
    return methods[identifier]

add

add(*endpoints) -> type[Self]

This group with more endpoints (read them from endpoints; declare them as attributes to type a client's methods).

ParameterTypeDescription
endpointsAnyEndpoint = ()

Returns type[Self]

@classmethod
def add(cls, *endpoints: AnyEndpoint) -> type[Self]:
    """This group with more endpoints (read them from ``endpoints``;
    declare them as attributes to type a client's methods)."""
    added = dict(cls.endpoints)
    for endpoint in endpoints:
        added[endpoint.identifier] = endpoint
    return cls._derive(endpoints=added)

prefix

prefix(prefix) -> type[Self]

This group with every endpoint under prefix.

ParameterTypeDescription
prefixstr

Returns type[Self]

@classmethod
def prefix(cls, prefix: str) -> type[Self]:
    """This group with every endpoint under ``prefix``."""
    return cls._derive(endpoints={k: e.prefix(prefix) for k, e in cls.endpoints.items()})

middleware

middleware(middleware) -> type[Self]

This group with every endpoint wrapped by middleware. Only the endpoints' run time changes; to type the handlers and clients, declare it as the group's type argument.

ParameterTypeDescription
middlewareAnyMiddleware

Returns type[Self]

@classmethod
def middleware(cls, middleware: AnyMiddleware) -> type[Self]:
    """This group with every endpoint wrapped by ``middleware``. Only the
    endpoints' run time changes; to type the handlers and clients,
    declare it as the group's type argument."""
    return cls._derive(
        endpoints={k: e.middleware(middleware) for k, e in cls.endpoints.items()}
    )

annotate

annotate[S, T](tag, value) -> type[Self]
ParameterTypeDescription
tagTagLike[S, T]
valueS

Returns type[Self]

@classmethod
def annotate[S, T](cls, tag: TagLike[S, T], value: S) -> type[Self]:
    return cls._derive(annotations=cls.annotations.add(tag, value))

annotate_merge

annotate_merge(annotations) -> type[Self]
ParameterTypeDescription
annotationsContext[Any]

Returns type[Self]

@classmethod
def annotate_merge(cls, annotations: Context[Any]) -> type[Self]:
    return cls._derive(annotations=cls.annotations.merge(annotations))

annotate_endpoints

annotate_endpoints[S, T](tag, value) -> type[Self]

This group with an annotation on every endpoint.

ParameterTypeDescription
tagTagLike[S, T]
valueS

Returns type[Self]

@classmethod
def annotate_endpoints[S, T](cls, tag: TagLike[S, T], value: S) -> type[Self]:
    """This group with an annotation on every endpoint."""
    return cls._derive(endpoints={k: e.annotate(tag, value) for k, e in cls.endpoints.items()})

annotate_endpoints_merge

annotate_endpoints_merge(annotations) -> type[Self]
ParameterTypeDescription
annotationsContext[Any]

Returns type[Self]

@classmethod
def annotate_endpoints_merge(cls, annotations: Context[Any]) -> type[Self]:
    return cls._derive(
        endpoints={k: e.annotate_merge(annotations) for k, e in cls.endpoints.items()}
    )

make

make(identifier, *, top_level=False) -> type[HttpApiGroup[Never]]

An empty group class (Effect's HttpApiGroup.make); add its endpoints with add.

ParameterTypeDescription
identifierstr
top_levelbool = False

Returns type[HttpApiGroup[Never]]

@staticmethod
def make(identifier: str, *, top_level: bool = False) -> type[HttpApiGroup[Never]]:
    """An empty group class (Effect's ``HttpApiGroup.make``); add its
    endpoints with ``add``."""
    return types.new_class(
        identifier,
        (HttpApiGroup,),
        {"identifier": identifier, "top_level": top_level},
    )