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#
| Type | Definition | Description |
|---|---|---|
AnyApi | type AnyApi = HttpApi[Any] |
Classes#
HttpApiApiWithApiServingReflectedEndpointAdditionalSchemasParseOptionsParamsParseOptionsQueryParseOptionsHeadersParseOptionsPayloadParseOptionsSuccessParseOptionsErrorParseOptionsSlotParseOptions
Functions#
api_of#
api_of(api) -> AnyApiThe HttpApi behind an ApiWith (every one is an HttpApi).
| Parameter | Type | Description |
|---|---|---|
api | ApiWith[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 apireflect#
reflect(api, *, on_group, on_endpoint, predicate=None) -> NoneVisit every group (with its merged annotations) and endpoint.
| Parameter | Type | Description |
|---|---|---|
api | AnyApi | |
on_group | Callable[[AnyGroup, Context[Any]], None] | |
on_endpoint | Callable[[ReflectedEndpoint], None] | |
predicate | Callable[[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) -> SlotParseOptionsEach slot's options: its own annotation, else ParseOptions.
| Parameter | Type | Description |
|---|---|---|
annotations | Context[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),
)