A client of an API served in memory (Effect's HttpApiTest).
groups(api, (Users,), layer=UsersLive) serves the handlers of the
listed groups without a server, and gives a client of the whole API; an
endpoint of another group dies when called::
api_client = yield from http_api.test.groups(api, (Users,), layer=UsersLive)
users = http_api.get_group(api_client, Users)The client, and the layer, are valid until the caller's Scope closes.
Without layer the groups' layers come from the context, which must
then outlive the client: a layer provided to groups(...) alone is
released once the client is made, as in Effect.
Functions#
groups#
groups[G, S: HttpApiGroup[Any, Any]](api: ApiServing[G, S], served: Sequence[type[S]], *, base_url: str = 'http://localhost:3000') -> Effect[Client[G], Never, S | Scope]
groups[G, S: HttpApiGroup[Any, Any], E, R](api: ApiServing[G, S], served: Sequence[type[S]], *, layer: Layer[S, E, R], base_url: str = 'http://localhost:3000') -> Effect[Client[G], E, R | Scope]A client of api whose requests are handled in memory by the
handlers of served (a group api lacks is a type error). The
groups' layers are layer, built into the caller's Scope, or
else come from the context; the client is valid until that scope
closes.
| Parameter | Type | Description |
|---|---|---|
api | ||
served | ||
layer | = None | |
base_url | = 'http://localhost:3000' |
@overload
def groups[G, S: HttpApiGroup[Any, Any]](
api: ApiServing[G, S],
served: Sequence[type[S]],
*,
base_url: str = "http://localhost:3000",
) -> Effect[Client[G], Never, S | Scope]: ...
@overload
def groups[G, S: HttpApiGroup[Any, Any], E, R](
api: ApiServing[G, S],
served: Sequence[type[S]],
*,
layer: Layer[S, E, R],
base_url: str = "http://localhost:3000",
) -> Effect[Client[G], E, R | Scope]: ...
def groups(
api: ApiServing[Any, Any],
served: Sequence[AnyGroup],
*,
layer: Layer[Any, Any, Any] | None = None,
base_url: str = "http://localhost:3000",
) -> Effect[Client[Any], Any, Any]:
"""A client of ``api`` whose requests are handled in memory by the
handlers of ``served`` (a group ``api`` lacks is a type error). The
groups' layers are ``layer``, built into the caller's ``Scope``, or
else come from the context; the client is valid until that scope
closes."""
return with_layer(lambda: _groups(api_of(api), served, base_url), layer)