GitHub

API reference for api.

HTTP APIs (Effect's HttpApi): groups of endpoints under one identifier, served by HttpApiBuilder, called with HttpApiClient and documented by OpenApi::

api = HttpApi.make("app").add(Users).add(Posts)  # HttpApi[Users | Posts]

Types

TypeDefinitionDescription
AnyApitype AnyApi = HttpApi[Any]

Classes

Functions

api_of

api_of(api) -> AnyApi

The HttpApi behind an ApiWith (every one is an HttpApi).

ParameterTypeDescription
apiApiWith[Any]

Returns AnyApi

def api_of(api: ApiWith[Any]) -> AnyApi:
    """The ``HttpApi`` behind an ``ApiWith`` (every one is an ``HttpApi``)."""
    if not isinstance(api, HttpApi):
        raise TypeError(f"api must be an HttpApi, got {type(api).__name__}")
    return api

reflect

reflect(api, *, on_group, on_endpoint, predicate=None) -> None

Visit every group (with its merged annotations) and endpoint.

ParameterTypeDescription
apiAnyApi
on_groupCallable[[AnyGroup, Context[Any]], None]
on_endpointCallable[[ReflectedEndpoint], None]
predicateCallable[[AnyGroup, AnyEndpoint], bool] | None = None
def reflect(
    api: AnyApi,
    *,
    on_group: Callable[[AnyGroup, Context[Any]], None],
    on_endpoint: Callable[[ReflectedEndpoint], None],
    predicate: Callable[[AnyGroup, AnyEndpoint], bool] | None = None,
) -> None:
    """Visit every group (with its merged annotations) and endpoint."""
    for group in api.groups.values():
        group_annotations = api.annotations.merge(group.annotations)
        on_group(group, group_annotations)
        for endpoint in group.endpoints.values():
            if predicate is not None and not predicate(group, endpoint):
                continue
            on_endpoint(
                ReflectedEndpoint(
                    group,
                    endpoint,
                    group_annotations.merge(endpoint.annotations),
                    endpoint.middlewares,
                    _response_content(
                        success_schemas(endpoint), api_schema.get_status_success_schema
                    ),
                    _response_content(error_schemas(endpoint), api_schema.get_status_error_schema),
                )
            )

get_slot_parse_options

get_slot_parse_options(annotations) -> SlotParseOptions

Each slot's options: its own annotation, else ParseOptions.

ParameterTypeDescription
annotationsContext[Any]

Returns SlotParseOptions

def get_slot_parse_options(annotations: Context[Any]) -> SlotParseOptions:
    """Each slot's options: its own annotation, else ``ParseOptions``."""
    fallback = annotations.get_option(ParseOptions)
    default: SchemaParseOptions = {} if fallback is None else fallback.value

    def slot(tag: type[Tag[SchemaParseOptions]]) -> SchemaParseOptions:
        found = annotations.get_option(tag)
        return default if found is None else found.value

    return SlotParseOptions(
        params=slot(ParamsParseOptions),
        query=slot(QueryParseOptions),
        headers=slot(HeadersParseOptions),
        payload=slot(PayloadParseOptions),
        success=slot(SuccessParseOptions),
        error=slot(ErrorParseOptions),
    )