Skip to content

Introduce fluent Response API and strict dispatcher return contract #470

Closed

Description

@armanist

Summary

Make the HTTP response API consistently fluent and require route actions / closures to return Response.

Goals

  • allow return $response->json(...)
  • allow return $response->html(...)
  • require route actions and closures to return Response
  • fail fast on invalid return types

In scope

  • src/Http/Traits/Response/Body.php
  • src/Http/Traits/Response/Header.php
  • src/Http/Traits/Response/Status.php
  • src/Router/RouteDispatcher.php
  • route dispatcher tests

Required API changes

These methods should return Response:

  • json()
  • html()
  • xml()
  • jsonp()
  • setHeader()
  • setStatusCode()
  • set()

Dispatcher contract

  • action return type must be Response
  • closure route return type must be Response
  • invalid non-Response return values should raise an exception

Acceptance criteria

  • fluent response builder API is available
  • route actions can return response builder calls directly
  • dispatcher returns the produced Response
  • invalid action / closure return values fail fast

Validation

  • route dispatcher unit tests
  • response trait unit tests
  • composer test
  • composer phpstan

Activity

  1. added a commit that references this issue on Apr 24, 2026
  2. added a commit that references this issue on Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions