The Game Panel Design record
The Game Panel
ADR-0018 Accepted

Use bespoke HTTP messages, not PSR-7

Created
Decided
Versions
History

Context

PSR-7 is a shared set of HTTP message interfaces for PHP, and PSR-15 adds handler and middleware interfaces over them. What they offer is interchangeability: middleware written against them works in any framework that implements them, and a message can be handed to any library that speaks the same interfaces.

The panel is one purpose-built system running as a single binary on one runtime, as ADR-0009 decides. Nothing outside it handles its messages: module authors write actions, and an action never sees a request object.

The interfaces are nearly a decade old. A message built to them takes its shape from that API rather than from what the panel needs.

Decision

I will define the engine's own request and response objects, and its own contracts for handling them. The panel will not implement PSR-7 or PSR-15, and nothing in it will depend on their interfaces.

Alternatives

Implementing PSR-7 and PSR-15, so that middleware written for other frameworks could run in the panel. I rejected this because that interchangeability buys nothing in a bespoke system where no code outside the engine holds a message, and it would put a dated API on every internal call site, shaping the design around the standard rather than around the panel.

Consequences

Easier:

  • The messages will be shaped around what the panel needs, and built as immutable value objects like the rest of the engine.
  • A request will describe what arrived and nothing more, since no interface will require an attribute bag for carrying state through a pipeline.

Harder:

  • Middleware written for other frameworks will not run in the panel. Any that is wanted will have to be written against the engine's own contracts.

Constrained:

  • Every component that handles a request or produces a response will depend on the engine's own message types.

Sources

  • Issue #62, Engine - HTTP, , edited through to narrow its scope and to state content directly rather than citing closed issues: the decision, which is created and decided, and its reasons: PSR-7 exists so middleware can be shared between frameworks, nothing outside the engine touches these classes because module authors write actions, and it would put a 2016-era API on every internal call site for no interoperability.
  • Issue #64, Engine - HTTP - Messages, : bespoke immutable messages built on property hooks and private(set), a request with no attribute bag, and the statement that the reasoning is recorded in #62.
  • The decision following the same reasoning as ADR-0004, that a PSR constrains how a design can be shaped and does not fit a bespoke system: first written down on .

Source adr/0018-bespoke-http-messages.md · commit d6910e4 · exported