PHPackages                             subtlephp/middlewares - 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. subtlephp/middlewares

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

subtlephp/middlewares
=====================

Hook into guzzle and do what you want

0.0.2(8y ago)0602MITPHP

Since Jul 15Pushed 8y agoCompare

[ Source](https://github.com/subtlephp/middlewares)[ Packagist](https://packagist.org/packages/subtlephp/middlewares)[ RSS](/packages/subtlephp-middlewares/feed)WikiDiscussions master Synced 2d ago

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

Do what needs to be done when you do a request with guzzle
==========================================================

[](#do-what-needs-to-be-done-when-you-do-a-request-with-guzzle)

1. Decide whether to retry when guzzle response is not OK
---------------------------------------------------------

[](#1-decide-whether-to-retry-when-guzzle-response-is-not-ok)

A service of 100 percent availability does not exist. So we must decide when to retry when a failure occurs.

Guzzle is a great HTTP client for PHP users and it provides a flexible mechanism to customize your request. When deciding when to retry, just tell guzzle whether to retry depending on response and when to retry after the 'failed' request.

2. Log both request and response (only when their bodies are readable for human)
--------------------------------------------------------------------------------

[](#2-log-both-request-and-response-only-when-their-bodies-are-readable-for-human)

3. Define your base\_uri and pattern once with '{}' marks and UriReplacer will do the rest.
-------------------------------------------------------------------------------------------

[](#3-define-your-base_uri-and-pattern-once-with--marks-and-urireplacer-will-do-the-rest)

### Installation

[](#installation)

`composer require subtlephp/middlewares`

### Prerequisites

[](#prerequisites)

Logger middleware depends on 2 constants, `REQUEST_ID` and `LOG_DIR`, but they are not must. `REQUEST_LOG` equals `''` and `LOG_DIR` equals `__DIR__` by default.

### Usage

[](#usage)

```
