PHPackages                             phpdot/http-middleware - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. phpdot/http-middleware

ActiveLibrary[HTTP &amp; Networking](/categories/http)

phpdot/http-middleware
======================

PSR-15 middlewares for PHPdot

v1.0.0(today)00MITPHPPHP &gt;=8.4

Since Jun 30Pushed todayCompare

[ Source](https://github.com/phpdot/http-middleware)[ Packagist](https://packagist.org/packages/phpdot/http-middleware)[ RSS](/packages/phpdot-http-middleware/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (9)Versions (2)Used By (0)

phpdot/http-middleware
======================

[](#phpdothttp-middleware)

PSR-15 middlewares for PHPdot

Install
-------

[](#install)

```
composer require phpdot/http-middleware
```

Quick Start
-----------

[](#quick-start)

Every middleware implements PSR-15 `MiddlewareInterface` and depends only on PSR interfaces, so it runs in any PSR-15 stack:

```
use PHPdot\HttpMiddleware\JsonBodyMiddleware;

// $responses and $streams are any PSR-17 factories (e.g. nyholm/psr7's Psr17Factory)
$middleware = new JsonBodyMiddleware($responses, $streams);

$response = $middleware->process($request, $handler);
```

### Inside the phpdot framework

[](#inside-the-phpdot-framework)

The middlewares are framework-agnostic — no `phpdot/http` dependency — so they slot into any PSR-15 pipeline. In a phpdot app, register one on the router:

```
$router->middleware(JsonBodyMiddleware::class);
```

The constructor's `ResponseFactoryInterface` and `StreamFactoryInterface` are resolved by the container (phpdot/http's `ResponseFactory` implements both).

---

Middlewares
-----------

[](#middlewares)

### `JsonBodyMiddleware`

[](#jsonbodymiddleware)

Parses an `application/json` request body into the PSR-7 parsed body, so handlers read `$request->getParsedBody()` instead of hand-decoding. A malformed body is rejected with `400` — once, centrally — rather than surfacing as a misleading validation error downstream.

- `application/json` is recognised (a `charset` suffix is fine); other content types pass through untouched.
- An empty body or a top-level scalar is left unparsed, for the handler to treat as empty.
- Malformed JSON → `400 {"error":"Malformed JSON request body."}`, and the handler is not called.

---

PSR Standards
-------------

[](#psr-standards)

PSRInterfaceUsagePSR-7`ServerRequestInterface`Request the middleware reads and augmentsPSR-7`ResponseInterface`Return typePSR-15`MiddlewareInterface`The contract every middleware implementsPSR-15`RequestHandlerInterface`The next handler in the pipelinePSR-17`ResponseFactoryInterface`Builds error responses (e.g. 400)PSR-17`StreamFactoryInterface`Builds response bodies---

Development
-----------

[](#development)

```
composer test        # Run tests
composer analyse     # PHPStan level 10
composer cs-fix      # Fix code style
composer cs-check    # Check code style (dry run)
composer check       # Run all three
```

License
-------

[](#license)

MIT

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62e82421bda4b5d6ba9a47ba6d88caca060dcd0d1a2862f351f3a97657385db0?d=identicon)[phpdot](/maintainers/phpdot)

---

Top Contributors

[![phpdot](https://avatars.githubusercontent.com/u/252500?v=4)](https://github.com/phpdot "phpdot (1 commits)")

---

Tags

httppsr-7jsonmiddlewarepsr-15

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpdot-http-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/phpdot-http-middleware/health.svg)](https://phpackages.com/packages/phpdot-http-middleware)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B3.8k](/packages/guzzlehttp-psr7)[cakephp/cakephp

The CakePHP framework

8.8k19.1M1.7k](/packages/cakephp-cakephp)[mezzio/mezzio

PSR-15 Middleware Microframework

3913.8M120](/packages/mezzio-mezzio)[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

577.0M95](/packages/laminas-laminas-stratigility)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28545.4k3](/packages/mezzio-mezzio-authentication-oauth2)[sunrise/http-router

A powerful solution as the foundation of your project.

17450.9k10](/packages/sunrise-http-router)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
