Skip to content

Response

Response markers are used to transform a response payload prior to passing it into a final response model.

Map dataclass

Map a payload to a dictionary under the specified key.

Source code in combadge/core/markers/response.py
@dataclass(**SLOTS)
class Map(ResponseMarker):
    """Map a payload to a dictionary under the specified key."""

    key: Any
    """Key under which the response will be mapped."""

    @override
    def __call__(self, response: Any, payload: Any) -> dict[Any, Any]:  # noqa: D102
        return {self.key: payload}

key instance-attribute

key: Any

Key under which the response will be mapped.

Extract dataclass

Extract a value from the specified key.

Source code in combadge/core/markers/response.py
@dataclass(**SLOTS)
class Extract(ResponseMarker):
    """Extract a value from the specified key."""

    key: Any
    """Key which will be extracted from the payload."""

    @override
    def __call__(self, response: Any, payload: Mapping[Any, Any]) -> Any:  # noqa: D102
        return payload[self.key]

key instance-attribute

key: Any

Key which will be extracted from the payload.

Mixin dataclass

Mix in the inner marker outputs to the payload.

Source code in combadge/core/markers/response.py
@dataclass(init=False)
class Mixin(ResponseMarker):
    """Mix in the inner marker outputs to the payload."""

    inner: Iterable[ResponseMarker]

    __slots__ = ("inner",)

    def __init__(self, *inner: ResponseMarker) -> None:
        """
        Initialize the marker.

        Args:
            *inner: inner markers to apply to a payload
        """
        self.inner = inner

    @override
    def __call__(self, response: Any, payload: _MutableMappingT) -> _MutableMappingT:  # noqa: D102
        for marker in self.inner:
            payload.update(marker(response, payload))
        return payload

__init__

__init__(*inner: ResponseMarker) -> None

Initialize the marker.

Parameters:

Name Type Description Default
*inner ResponseMarker

inner markers to apply to a payload

()
Source code in combadge/core/markers/response.py
def __init__(self, *inner: ResponseMarker) -> None:
    """
    Initialize the marker.

    Args:
        *inner: inner markers to apply to a payload
    """
    self.inner = inner