PHPackages                             api-clients/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. api-clients/middleware

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

api-clients/middleware
======================

Request middleware

4.0.0(9y ago)1115.9k↓50.7%3[4 PRs](https://github.com/php-api-clients/middleware/pulls)16MITPHPPHP ^7.0

Since Dec 5Pushed 2y ago2 watchersCompare

[ Source](https://github.com/php-api-clients/middleware)[ Packagist](https://packagist.org/packages/api-clients/middleware)[ RSS](/packages/api-clients-middleware/feed)WikiDiscussions master Synced yesterday

READMEChangelog (6)Dependencies (7)Versions (14)Used By (16)

API Client middleware for PHP 7.x
=================================

[](#api-client-middleware-for-php-7x)

[![Build Status](https://camo.githubusercontent.com/1847c0c1c44efc340da459f7b4512c0a5fe8f9f5c48a1fa4cbbd32a5d4f47564/68747470733a2f2f7472617669732d63692e6f72672f7068702d6170692d636c69656e74732f6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/php-api-clients/middleware)[![Latest Stable Version](https://camo.githubusercontent.com/e1356259a0a165ef4a8bc44cad59e6635f86b7e656229bad395975f29515e98c/68747470733a2f2f706f7365722e707567782e6f72672f6170692d636c69656e74732f6d6964646c65776172652f762f737461626c652e706e67)](https://packagist.org/packages/api-clients/middleware)[![Total Downloads](https://camo.githubusercontent.com/fc0aaaeb4a18d80fdd3f32456241cc59b4dab83d6d99bae8a8bb909522ac1e4d/68747470733a2f2f706f7365722e707567782e6f72672f6170692d636c69656e74732f6d6964646c65776172652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/api-clients/middleware/stats)[![Code Coverage](https://camo.githubusercontent.com/37ce9c4076649930efcb4b3f0b57d2f741609e542430c4c4773b0eb290bc3e5c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068702d6170692d636c69656e74732f6d6964646c65776172652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/php-api-clients/middleware/?branch=master)[![License](https://camo.githubusercontent.com/f32daa3afb6a80b7f1f8e9a7e5508c48e0df1c71c2a9545c853a3ebc77a618bb/68747470733a2f2f706f7365722e707567782e6f72672f6170692d636c69656e74732f6d6964646c65776172652f6c6963656e73652e706e67)](https://packagist.org/packages/api-clients/middleware)[![PHP 7 ready](https://camo.githubusercontent.com/0489afcfe51a09417c861bf5a006d7d9ce5b47ac4774596480e01fa02ef44cb4/687474703a2f2f7068703772656164792e74696d6573706c696e7465722e63682f7068702d6170692d636c69656e74732f6d6964646c65776172652f62616467652e737667)](https://appveyor-ci.org/php-api-clients/middleware)

This library contains the a async `MiddlewareRunner` used in our api clients. It provides an interface for all middlewares. Middlewares are ordered by priority when they where added to the `MiddlewareRunner`. Order of middlewares with the same priority is not guaranteed.

A number of traits are provided for your convenience, if your middleware implementation does not require all the methods defined in the `MiddlewareInterface`.

Locator
-------

[](#locator)

The locator can be used by your application to fetch middleware instances. It will check whether the created instance implements the `MiddlewareInterface`. Currently the only provided locator is the `ContainerLocator` which accepts a `Psr\Container\ContainerInterface` to fetch your middleware instances.

Example
-------

[](#example)

```
    $container = /* ... */;
    $locator = new ContainerLocator($container);
    $middlewares = [];

    $config = [
        'middlewares' => [/*...*/]
        'options' => [/*...*/]
    ];

    foreach ($config['middlewares'] as $middleware) {
       $middlewares[] = $locator->get($middleware);
    }

    $runner = new MiddlewareRunner($config['options'], $middelwares);

    $runner->pre($request)->then(function ($request) use ($options) {
        return resolve($this->browser->send(
            $request
        ));
    }, function (ResponseInterface $response) {
        return resolve($response);
    })->then(function (ResponseInterface $response) use ($runner) {
        return $runner->post($response);
    })->otherwise(function (Throwable $throwable) use ($runner) {
        return reject($runner->error($throwable));
    });
```

License
=======

[](#license)

The MIT License (MIT)

Copyright (c) 2017 Cees-Jan Kiewiet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community26

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 87% 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 ~40 days

Total

6

Last Release

3291d ago

Major Versions

1.1.0 → 2.0.02017-03-04

2.0.1 → 3.0.02017-06-27

3.0.0 → 4.0.02017-06-28

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/147145?v=4)[Cees-Jan Kiewiet](/maintainers/WyriHaximus)[@WyriHaximus](https://github.com/WyriHaximus)

---

Top Contributors

[![WyriHaximus](https://avatars.githubusercontent.com/u/147145?v=4)](https://github.com/WyriHaximus "WyriHaximus (267 commits)")[![dependabot-support](https://avatars.githubusercontent.com/u/112581971?v=4)](https://github.com/dependabot-support "dependabot-support (16 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (14 commits)")[![jaapio](https://avatars.githubusercontent.com/u/1060433?v=4)](https://github.com/jaapio "jaapio (5 commits)")[![ivailo-stoianov](https://avatars.githubusercontent.com/u/5235174?v=4)](https://github.com/ivailo-stoianov "ivailo-stoianov (2 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (2 commits)")[![mdrost](https://avatars.githubusercontent.com/u/4083346?v=4)](https://github.com/mdrost "mdrost (1 commits)")

---

Tags

hacktoberfestmiddlewarephpphp7reactphp

### Embed Badge

![Health badge](/badges/api-clients-middleware/health.svg)

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[retailcrm/api-client-php

PHP client for RetailCRM API

681.1M1](/packages/retailcrm-api-client-php)[mimmi20/browser-detector

Library to detect Browsers and Devices

48157.5k5](/packages/mimmi20-browser-detector)

PHPackages © 2026

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