PHPackages                             psg/psr-101 - 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. psg/psr-101

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

psg/psr-101
===========

PSR 15 remake into AppInterface

0.4(4y ago)0172MITPHPPHP &gt;=5.3.0

Since Jul 9Pushed 4y ago1 watchersCompare

[ Source](https://github.com/PHP-SG/psr-101)[ Packagist](https://packagist.org/packages/psg/psr-101)[ Docs](https://github.com/php-sg/psr-100)[ RSS](/packages/psg-psr-101/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (5)Used By (2)

==== This is not a FIG PSR and has not undergone the rigorous process to become one ====

PSR 101
=======

[](#psr-101)

This is a rewrite of PSR 15, and an inclusion of PSR 17 into the MiddlewareAppInterface. Various ideas went into this:

- Because the inteface method parameters must match (see PSR 100 README), and because PSR 101 middleware required the handler to be the extended version of the RequestionHandlerInterface, PSR 15 could not be extended for the middleware interfaces
- To write standardized middleware, the method of using PSR 17 factories should be standardized
    - To do this, the MiddlewareAppInterface provides access to those factories
- Some middleware does not care about the App, it only wants a closure for a `next` call. This type of middleware is separately provided for as `MiddlewareNextInterface`
    - Apps should handle this sort of middleware by detecting which type of middleware and applying correctly
- Middleware is expected with MiddlewareAppInterface. As such there are methods for adding, removing and checking middleware.
    - These methods are the uncontexted `has`, `add`, `remove`. The expectation here is that frameworks will generally not have these methods on their $app object (b/c they are too general), but that, it would make sense for these methods to refer to middleware. Further, to add something like `addMiddleware` to the interface potentially conflicts with existing methods on $app objects of frameworks.

Use
---

[](#use)

Let's see a middleware based on this PSR 101

```
use Psg\Psr100\Factory\Psr100Factory;
use Psg\Http\Message\{ResponseInterface, ServerRequestInterface};
use Psg\Http\Server\{MiddlewareAppInterface, MiddlewareInterface, MiddlewareNextInterface};

class App extends Psr100Factory implements MiddlewareAppInterface{
	public $middleware;
	public function __construct(){
		$this->middleware = new \SplObjectStorage();
	}
	public function handle(\Psr\Http\Message\ServerRequestInterface $request): ResponseInterface {
		$middleware = $this->middleware->current();
		$this->middleware->next();
		return $middleware->process($request, $this);
	}
	public function add($middleware){
		$this->middleware->attach($middleware);
	}
	public function remove($middleware){
		$this->middleware->detach($middleware);
	}
	public function has($middleware){
		return $this->middleware->contains($middleware);
	}
}

class Control implements MiddlewareInterface {
	public function process(ServerRequestInterface $request, MiddlewareAppInterface $app): ResponseInterface {
		return $app->createResponse(200)->withBody($app->createStream('there is one name in programming, and that name is bill'));
	}
}
class MiddleOut implements MiddlewareInterface {
	public function process(ServerRequestInterface $request, MiddlewareAppInterface $app): ResponseInterface {
		$response = $app->handle($request);
		$only_bob = preg_replace('/bill/i', 'bob', (string)$response->getbody());
		$new_stream = $response->getBody()->create($only_bob);
		return $response->withBody($new_stream);
	}
}

$App = new App;
$App->add(new MiddleOut);
$App->add(new Control);
$App->middleware->rewind();
$response = $App->handle($App->createServerRequest('get', 'http://bobery.com/'));
echo (string)$response->getBody();

#> there is one name in programming, and that name is bob
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

Every ~0 days

Total

4

Last Release

1766d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4543facab3c88d548b98d8472b532faf7bcd00555cc47c0dc808d935f8d3d73f?d=identicon)[grithin](/maintainers/grithin)

---

Top Contributors

[![grithin](https://avatars.githubusercontent.com/u/7241358?v=4)](https://github.com/grithin "grithin (6 commits)")

---

Tags

httpresponserequestpsrhttp-messagefactorypsr-101

### Embed Badge

![Health badge](/badges/psg-psr-101/health.svg)

```
[![Health](https://phpackages.com/badges/psg-psr-101/health.svg)](https://phpackages.com/packages/psg-psr-101)
```

###  Alternatives

[psr/http-message

Common interface for HTTP messages

7.1k1.0B5.5k](/packages/psr-http-message)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k692.9M1.9k](/packages/psr-http-factory)[fig/http-message-util

Utility classes and constants for use with PSR-7 (psr/http-message)

39489.0M274](/packages/fig-http-message-util)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

153.3k](/packages/art4-requests-psr18-adapter)

PHPackages © 2026

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