Skip to content

feat: add JsonBodyParser middleware#1

Merged
ralflang merged 1 commit into
FRAMEWORK_6_0from
feat/json-body-parser
Mar 7, 2026
Merged

feat: add JsonBodyParser middleware#1
ralflang merged 1 commit into
FRAMEWORK_6_0from
feat/json-body-parser

Conversation

@ralflang
Copy link
Copy Markdown
Member

@ralflang ralflang commented Mar 7, 2026

Implements PSR-15 middleware for parsing JSON request bodies into parsed body attributes, with proper PSR-7 stream rewinding and error handling for malformed JSON.

Add JsonBodyParser middleware that solves the php://input non-seekable
stream issue by reading the request body once and caching the parsed
JSON in the request's parsedBody property.

This implements the standard PSR-7 pattern for handling request bodies,
allowing controllers to use getParsedBody() instead of reading the
stream directly.

Usage:
  $mapper->connect('route', '/path', [
      'controller' => MyController::class,
      'stack' => [JsonBodyParser::class],
  ]);

In controllers:
  $body = $request->getParsedBody(); // array|null

Refs: PSR-7 ServerRequestInterface::getParsedBody()
@ralflang ralflang merged commit 20c4caa into FRAMEWORK_6_0 Mar 7, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant