Response Adapter¶
response_adapter
¶
Protocol for translating application output into transport-level responses.
ResponseAdapter
¶
Bases: Protocol
Translates application-layer output into a transport response.
Implementations handle transport-specific serialization (e.g.
JSON encoding, setting HTTP status headers, formatting CLI
output) and produce the raw response type consumed by the
transport framework.
Example
class OrderResponse:
def __init__(self, order_id: str, status: str) -> None:
self.order_id = order_id
self.status = status
class JsonResponseAdapter:
def adapt(self, output: object) -> object:
return {"data": output}
adapter = JsonResponseAdapter()
response = adapter.adapt(OrderResponse(order_id="42", status="paid"))
# response is a JSON-serializable dict
Source code in src/forging_blocks/presentation/adapters/response_adapter.py
adapt(output: UseCaseOutput) -> RawResponse
¶
Convert successful use-case output into a transport response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
UseCaseOutput
|
The value returned by |
required |
Returns:
| Type | Description |
|---|---|
RawResponse
|
A transport-level response ready to send to the caller. |
Source code in src/forging_blocks/presentation/adapters/response_adapter.py
adapt_error(view_model: ErrorViewModel) -> RawResponse
¶
Convert an ErrorViewModel into a transport error response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_model
|
ErrorViewModel
|
The error view model produced by |
required |
Returns:
| Type | Description |
|---|---|
RawResponse
|
A transport-level error response (e.g. an HTTP response |
RawResponse
|
with the appropriate status code and JSON body). |