componenta / http-body-parsing-middleware
PSR-15 request body parsing middleware for Componenta
Package info
github.com/componenta/http-body-parsing-middleware
pkg:composer/componenta/http-body-parsing-middleware
Requires
- php: ^8.4
- componenta/config: ^1.0
- psr/container: ^2.0
- psr/http-message: ^2.0
- psr/http-server-middleware: ^1.0
README
PSR-15 middleware for parsing HTTP request bodies into PSR-7 parsed body and uploaded files. It supports JSON, application/x-www-form-urlencoded, and multipart/form-data.
Use this package in HTTP applications that need parsed bodies for methods and content types PHP does not parse natively.
Installation
composer require componenta/http-body-parsing-middleware
The package exposes Componenta\Http\Middleware\BodyParsingConfigProvider through Composer metadata.
Configuration
The config provider registers BodyParsingMiddleware from:
StreamFactoryInterfaceUploadedFileFactoryInterface
Install one PSR-7/PSR-17 integration package so these factories exist in the container.
Runtime Behavior
The middleware skips requests when:
getParsedBody()is already set;- the method is
GET,HEAD,OPTIONS, orTRACE; - PHP has already parsed a native
POSTform or multipart request.
Scalar JSON values are preserved under the __scalar key because PSR-7 parsed bodies must be null, array, or object.
Public Classes
BodyParsingMiddlewareis the PSR-15 middleware.Body\MultipartParserparses multipart bodies.Body\MultipartPartrepresents one multipart part.
Related Packages
componenta/http-psrwires server request creation.componenta/app-httpruns HTTP middleware.