Skip to content

[serializer] provide result-to-http helper #118

@imdhemy

Description

@imdhemy

The Result Type pattern is a common FP pattern for expressing success/failure explicitly. We need a framework helper that works with the normalizer component to be used in the interface layer to consistently convert Result values into HTTP responses, including both serialized success resources and mapped errors.

Motivation:
Today, controllers often duplicate response-shaping logic. A dedicated helper would:

  • Standardize success/error HTTP mapping
  • Keep controllers thin and consistent
  • Reuse the existing normalizer for resource serialization
  • Improve type safety and maintainability across endpoints

Proposal:
Add createResultToHttpMapper to the serializer/http utilities so applications can:

  • Map success results to { status, body: { data: ... } }
  • Serialize success payloads through normalizer options
  • Map typed errors to configured HTTP statuses
  • Define fallback behavior for unmapped errors

Note: Here is an implementation from Kairos.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions