PHPackages                             coolblue/http-client-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. coolblue/http-client-middleware

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

coolblue/http-client-middleware
===============================

A middleware solution for PSR-18 compliant http clients.

1.2.0(2y ago)10192.8k↓65.8%4[1 PRs](https://github.com/coolblue/php-http-client-middleware/pulls)MITPHPPHP ^8.0CI failing

Since Feb 25Pushed 6mo ago4 watchersCompare

[ Source](https://github.com/coolblue/php-http-client-middleware)[ Packagist](https://packagist.org/packages/coolblue/http-client-middleware)[ RSS](/packages/coolblue-http-client-middleware/feed)WikiDiscussions main Synced yesterday

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

HTTP Client middleware
======================

[](#http-client-middleware)

HTTP Client middleware is a middleware solution for [PSR-18 (HTTP Client)](http://www.php-fig.org/psr/psr-18).

This package contains both a middleware interface as well as a ready to use HTTP Client that is capable of handling middleware.

**NB** This package does not contain any middleware implementations.

Rationale
---------

[](#rationale)

The interface offered by PSR-18 (HTTP Client) does not offer any (configuration) options offered by known HTTP abstractions - for example Guzzle and Symfony HttpClient. This makes implementations of this interface exchangeable, but does require you to write these configurations yourself. This can mean additional code that is repeated in multiple locations. Something that might be undesirable.

This might be solved by using a solution similar to the middleware defined in [PSR-15 (HTTP Server Request Handlers)](https://www.php-fig.org/psr/psr-15). Using middleware will allow centralization of functionality without the necessity of extending or wrapping a client. It also enables you to perform actions both *before* performing the actual request and *after* the actual request.

Installation
------------

[](#installation)

```
composer require coolblue/http-client-middleware
```

Usage
-----

[](#usage)

Middleware needs to comply to the interface `\Coolblue\Http\Client\MiddlewareInterface`:

```
