PHPackages                             jhoffland/guzzle-formatter - 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. jhoffland/guzzle-formatter

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

jhoffland/guzzle-formatter
==========================

PHP Guzzle request/response to HTTP message formatter

1.5(3y ago)0259MITPHPPHP &gt;=7.4

Since Mar 30Pushed 3y ago1 watchersCompare

[ Source](https://github.com/jhoffland/guzzle-formatter)[ Packagist](https://packagist.org/packages/jhoffland/guzzle-formatter)[ Docs](https://github.com/jhoffland/guzzle-formatter)[ RSS](/packages/jhoffland-guzzle-formatter/feed)WikiDiscussions main Synced 4w ago

READMEChangelogDependencies (4)Versions (7)Used By (0)

Guzzle Formatter
================

[](#guzzle-formatter)

[![Tests status](https://github.com/joephoffland/guzzle-formatter/actions/workflows/testing.yml/badge.svg)](https://github.com/jhoffland/guzzle-formatter/actions/workflows/testing.yml)[![StyleCI status](https://camo.githubusercontent.com/5a5de73b626c0028a8c19f60fbd79ef8e9bdc996a415d5edebbf3de95f0bf081/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3437303931373330342f736869656c643f7374796c653d666c6174266272616e63683d6d61696e)](https://github.styleci.io/repos/470917304?branch=main)

PHP library for formatting Guzzle requests and responses to [HTTP messages](https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages).

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

[](#installation)

[![Latest stable version](https://camo.githubusercontent.com/3a8fbbbe73d014421a130f2491c224e57fb1cac75b545446c4157177b4323c78/687474703a2f2f706f7365722e707567782e6f72672f6a686f66666c616e642f67757a7a6c652d666f726d61747465722f76)](https://packagist.org/packages/jhoffland/guzzle-formatter)[![Total downloads](https://camo.githubusercontent.com/4a7d6b38429505c0009cce9aa9f5ce3867d7b2ba5e9b1737ae495c689f7a5c0b/687474703a2f2f706f7365722e707567782e6f72672f6a686f66666c616e642f67757a7a6c652d666f726d61747465722f646f776e6c6f616473)](https://packagist.org/packages/jhoffland/guzzle-formatter)

Install this library directly with Composer:

```
composer require jhoffland/guzzle-formatter
```

Add `--dev` if this library is not needed in a production environment.

Usage
-----

[](#usage)

```
use GuzzleFormatter\RequestFormatter;
use GuzzleFormatter\ResponseFormatter;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

$request = new Request('GET', 'https://github.com/jhoffland/guzzle-formatter');
echo (new RequestFormatter())->http($request); // Results in the formatted HTTP request message.

$response = (new Client())->send($request);
echo (new ResponseFormatter())->http($response); // Results in the formatted HTTP response message.
```

### Using middleware

[](#using-middleware)

Logging all requests performed and/or responses received by a Guzzle client, using [middleware](https://docs.guzzlephp.org/en/stable/handlers-and-middleware.html#middleware).

The HTTP request and/or response messages are written to the file, specified when creating the `HttpFormatterMiddleware` class instance.

```
use GuzzleFormatter\Middleware\HttpFormatterMiddleware;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;

$formatterMiddleware = new HttpFormatterMiddleware('/path/to/output-file.txt');

$handlerStack = HandlerStack::create();

$handlerStack->after('prepare_body', $formatterMiddleware->requests(), 'http_request_formatter');
$handlerStack->after('prepare_body', $formatterMiddleware->responses(), 'http_response_formatter');

$client = new Client([
    'handler' => $handlerStack,
]);
$client->get('https://github.com/jhoffland/guzzle-formatter');
```

### Available options

[](#available-options)

#### 1. End of Line character

[](#1-end-of-line-character)

Available when creating an instance of [`RequestFormatter`](src/RequestFormatter.php) &amp; [`ResponseFormatter`](src/ResponseFormatter.php).

#### 2. Hide sensitive headers

[](#2-hide-sensitive-headers)

Available for when formatting an HTTP message with [`RequestFormatter`](src/RequestFormatter.php) &amp; [`ResponseFormatter`](src/ResponseFormatter.php) &amp; when creating an instance of [`HttpFormatterMiddleware`](src/Middleware/HttpFormatterMiddleware.php).
The headers seen as sensitive can be found in the array [`Formatter::SENSITIVE_HEADERS`](src/Formatter.php).

Supported PHP &amp; package versions
------------------------------------

[](#supported-php--package-versions)

[![PHP version](https://camo.githubusercontent.com/f607f176cfbd636f6e985fd99a9147a9e9eae5732e9b4957678862d96b3c6590/687474703a2f2f706f7365722e707567782e6f72672f6a686f66666c616e642f67757a7a6c652d666f726d61747465722f726571756972652f706870)](composer.json)[![Guzzle version](https://camo.githubusercontent.com/869a27462e58025ec6da38294dfd95978978e25acbb266146dd7b001e8cdd9a8/68747470733a2f2f706f7365722e707567782e6f72672f6a686f66666c616e642f67757a7a6c652d666f726d61747465722f726571756972652f67757a7a6c65687474702f67757a7a6c65)](composer.json)

This library is tested with PHP 7.4, 8.0 and 8.1.
Check the [`composer.json`](composer.json) file for the supported package versions.

Feel free to add support for additional versions to this library.

Contributing
------------

[](#contributing)

Feel free to contribute to this library. Contribute by forking the [GitHub repository](https://github.com/jhoffland/guzzle-formatter) and opening a pull request.
When opening a pull request, please make sure that:

- The pull request has a clear title;
- The pull request does not consist of too many (unnecessary/small) commits;
- The [StyleCI](https://github.styleci.io/repos/470917304) analysis pass;
- The PHPUnit tests pass.

ToDo's
------

[](#todos)

- Add test for formatting request when making an request to an URL without path (e.g. to  instead of to ).
- Add test for hiding and not-hiding sensitive headers when using the `HttpFormatterMiddleware`.
- Add cURL formatter.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Every ~40 days

Recently: every ~51 days

Total

6

Last Release

1297d ago

PHP version history (2 changes)1.0PHP ^7.4

1.5PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c1e0df0ab69d3bf5d26b763af3ac8954de1090b90613fdbab6f745b080c96ff?d=identicon)[jhoffland](/maintainers/jhoffland)

---

Top Contributors

[![jhoffland](https://avatars.githubusercontent.com/u/33959957?v=4)](https://github.com/jhoffland "jhoffland (9 commits)")

---

Tags

guzzlehttpphphttpformatterGuzzleformatting

###  Code Quality

TestsPHPUnit

Static AnalysisRector

### Embed Badge

![Health badge](/badges/jhoffland-guzzle-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/jhoffland-guzzle-formatter/health.svg)](https://phpackages.com/packages/jhoffland-guzzle-formatter)
```

###  Alternatives

[kevinrob/guzzle-cache-middleware

A HTTP/1.1 Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack. (RFC 7234)

43117.4M104](/packages/kevinrob-guzzle-cache-middleware)[php-http/guzzle7-adapter

Guzzle 7 HTTP Adapter

9057.1M554](/packages/php-http-guzzle7-adapter)[graham-campbell/guzzle-factory

Provides A Simple Guzzle Factory With Good Defaults

916.4M49](/packages/graham-campbell-guzzle-factory)[graze/guzzle-jsonrpc

JSON-RPC 2.0 client for Guzzle

981.2M24](/packages/graze-guzzle-jsonrpc)[kozz/laravel-guzzle-provider

Guzzle 5/6 Service Provider for Laravel

621.1M2](/packages/kozz-laravel-guzzle-provider)[amphp/http-client-guzzle-adapter

Guzzle adapter for Amp's HTTP client.

1523.6k1](/packages/amphp-http-client-guzzle-adapter)

PHPackages © 2026

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