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#
| Attribute | Type | Description |
|---|---|---|
identifier | str | |
top_level | bool | |
endpoints | Mapping[str, AnyEndpoint] | |
annotations | Context[Any] | |
origin | type[HttpApiGroup[Any]] | The class whose handlers this group's are: itself, or the group it
was derived from with |
Functions#
method#
method(identifier) -> AnyOn 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).
| Parameter | Type | Description |
|---|---|---|
identifier | str |
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).
| Parameter | Type | Description |
|---|---|---|
endpoints | AnyEndpoint = () |
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.
| Parameter | Type | Description |
|---|---|---|
prefix | str |
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.
| Parameter | Type | Description |
|---|---|---|
middleware | AnyMiddleware |
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]| Parameter | Type | Description |
|---|---|---|
tag | TagLike[S, T] | |
value | S |
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]| Parameter | Type | Description |
|---|---|---|
annotations | Context[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.
| Parameter | Type | Description |
|---|---|---|
tag | TagLike[S, T] | |
value | S |
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]| Parameter | Type | Description |
|---|---|---|
annotations | Context[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.
| Parameter | Type | Description |
|---|---|---|
identifier | str | |
top_level | bool = 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},
)