GitHub

HttpApiEndpoint

API reference for HttpApiEndpoint.

An endpoint. params, query and headers are the string tree codecs of their schemas, payload the payload schemas by content type, success and error the response schemas (their JSON codecs unless disable_codecs).

Attributes

AttributeTypeDescription
identifierstr
methodHttpMethod
pathstr
paramsTop | None = None
queryTop | None = None
headersTop | None = None
payloadPayloadMap = field(default_factory=(dict[str, PayloadEntry]))
successtuple[Top, ...] = ()
errortuple[Top, ...] = ()
annotationsContext[Any] = field(default_factory=(Context.empty))
middlewarestuple[AnyMiddleware, ...] = ()
disable_codecsbool = False

Functions

__init__

__init__(identifier, method, path, params=None, query=None, headers=None, payload=dict[str, PayloadEntry](), success=(), error=(), annotations=Context.empty(), middlewares=(), disable_codecs=False) -> None
ParameterTypeDescription
identifierstr
methodHttpMethod
pathstr
paramsTop | None = None
queryTop | None = None
headersTop | None = None
payloadPayloadMap = dict[str, PayloadEntry]()
successtuple[Top, ...] = ()
errortuple[Top, ...] = ()
annotationsContext[Any] = Context.empty()
middlewarestuple[AnyMiddleware, ...] = ()
disable_codecsbool = False

prefix

prefix(prefix) -> Self

This endpoint under prefix.

ParameterTypeDescription
prefixstr

Returns Self

def prefix(self, prefix: str) -> Self:
    """This endpoint under ``prefix``."""
    return replace(self, path=prefix_path(self.path, prefix))

middleware

middleware[T: HttpApiMiddleware[Any, Any, Any]](middleware) -> HttpApiEndpoint[P_co, Q_co, B_co, CB_co, H_co, S, CS_co, E, M_co | T, MT_co | T]

This endpoint wrapped by middleware: its handler may fail with the middleware's errors, a client too, and the services it provides are the handler's. The group layer needs the middleware.

ParameterTypeDescription
middlewaretype[T]

Returns HttpApiEndpoint[P_co, Q_co, B_co, CB_co, H_co, S, CS_co, E, M_co | T, MT_co | T]

def middleware[T: HttpApiMiddleware[Any, Any, Any]](
    self, middleware: type[T], /
) -> HttpApiEndpoint[P_co, Q_co, B_co, CB_co, H_co, S, CS_co, E, M_co | T, MT_co | T]:
    """This endpoint wrapped by ``middleware``: its handler may fail
    with the middleware's errors, a client too, and the services it
    provides are the handler's. The group layer needs the middleware."""
    if middleware in self.middlewares:
        return self
    return replace(self, middlewares=(*self.middlewares, middleware))

annotate

annotate[A, T](tag, value) -> Self

This endpoint with an annotation (OpenApi.Summary, ...).

ParameterTypeDescription
tagTagLike[A, T]
valueA

Returns Self

def annotate[A, T](self, tag: TagLike[A, T], value: A) -> Self:
    """This endpoint with an annotation (``OpenApi.Summary``, ...)."""
    return replace(self, annotations=self.annotations.add(tag, value))

annotate_merge

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

Returns Self

def annotate_merge(self, annotations: Context[Any]) -> Self:
    return replace(self, annotations=self.annotations.merge(annotations))

pipe

pipe[A](f) -> A
ParameterTypeDescription
fCallable[[Self], A]

Returns A

def pipe[A](self, f: Callable[[Self], A], /) -> A:
    return f(self)