PHPackages                             jenky/hermes - 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. jenky/hermes

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

jenky/hermes
============

Laravel guzzle manager

1.4.1(5y ago)1677MITPHPPHP ^7.1.3|^8.0CI failing

Since Nov 4Pushed 4y ago1 watchersCompare

[ Source](https://github.com/jenky/hermes)[ Packagist](https://packagist.org/packages/jenky/hermes)[ Docs](https://github.com/jenky/hermes)[ RSS](/packages/jenky-hermes/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (6)Versions (19)Used By (0)

Hermes
======

[](#hermes)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a0af6bab8f13be35e08b0e47799e4b5bbfa9701029fb2b22114b9573eedd1560/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a656e6b792f6865726d65732e737667)](https://packagist.org/packages/jenky/hermes)[![Test Status](https://github.com/jenky/hermes/workflows/Tests/badge.svg)](https://github.com/jenky/hermes/actions)[![Quality Score](https://camo.githubusercontent.com/bd4c8f4109d2ca76b350b569f994a86c4968fc68478ce3f9b7a8eddcf579644a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6a656e6b792f6865726d65732e737667)](https://scrutinizer-ci.com/g/jenky/hermes)[![Codecov](https://camo.githubusercontent.com/28184289c168c41bd2a07a35cf124911e0838238ed51a1d8d2112a5f47a83092/68747470733a2f2f636f6465636f762e696f2f67682f6a656e6b792f6865726d65732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/jenky/hermes)[![Total Downloads](https://camo.githubusercontent.com/bab6a5ef54f5e73539578478256d4912ee4b32623060c349f230d068e8fffc94/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a656e6b792f6865726d65732e737667)](https://packagist.org/packages/jenky/hermes)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE.md)

The package provides a nice and easy wrapper around Guzzle for use in your Laravel applications. If you don't know what Guzzle does, [take a peek at their intro](http://docs.guzzlephp.org/en/stable/index.html). Shortly said, Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web service.

- [Hermes](#hermes)
    - [Install](#install)
    - [Configuration](#configuration)
        - [Channel configuration](#channel-configuration)
        - [Configure the guzzle option](#configure-the-guzzle-option)
        - [Configure the guzzle handler](#configure-the-guzzle-handler)
        - [Configure the guzzle middleware](#configure-the-guzzle-middleware)
        - [Customizing the guzzle handler stack](#customizing-the-guzzle-handler-stack)
            - ["Tap" class parameters](#tap-class-parameters)
    - [Middleware](#middleware)
        - [`RequestEvent`](#requestevent)
        - [`ResponseHandler`](#responsehandler)
    - [Usage](#usage)
    - [Change log](#change-log)
    - [Testing](#testing)
    - [Contributing](#contributing)
    - [Security](#security)
    - [Credits](#credits)
    - [License](#license)

Install
-------

[](#install)

You may use Composer to install Hermes into your Laravel project:

```
$ composer require jenky/hermes
```

After installing Hermes, publish its assets using the `vendor:publish` Artisan command.

```
php artisan vendor:publish
```

or

```
php artisan vendor:publish --provider="Jenky\Hermes\HermesServiceProvider"
```

Configuration
-------------

[](#configuration)

After publishing Hermes's assets, its primary configuration file will be located at `config/hermes.php`. This configuration file allows you to configure your guzzle client options and each configuration option includes a description of its purpose, so be sure to thoroughly explore this file.

### Channel configuration

[](#channel-configuration)

A channel is simply a guzzle http client instance with its own configuration. This allows you to create a http client on the fly and reuse anytime, anywhere you want.

### Configure the guzzle option

[](#configure-the-guzzle-option)

Set guzzle request options within the channel. Please visit [Request Options](http://docs.guzzlephp.org/en/stable/request-options.html) for more information.

```
'default' => [
    'options' => [
        'base_uri' => 'https://api.github.com/v3/',
        'time_out' => 20,
    ],
],
```

### Configure the guzzle handler

[](#configure-the-guzzle-handler)

Configure guzzle [Handler](http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html#handlers) within the channel.

By default, guzzle will choose the most appropriate handler based on the extensions available on your system. However you can override this behavior with `handler` option. Optionally, any constructor parameters the handler needs may be specified using the `with` configuration option:

```
'default' => [
    'handler' => App\Http\CustomCurlHandler::class,
    'with' => [
        'delay' => 5,
    ],
],
```

An alternative way is set the handler in the [`options`](#configure-the-guzzle-option) configuration:

```
'default' => [
    'options' => [
        'handler' => App\Http\CustomCurlHandler::create(['delay' => 5]),
    ],
],
```

### Configure the guzzle middleware

[](#configure-the-guzzle-middleware)

Configure guzzle [Middleware](http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html#middleware) within the channel.

```
'default' => [
    'middleware' => [
        Jenky\Hermes\Middleware\RequestEvent::class,
    ],
],
```

You can read about the middleware in the [middleware](#middleware) section.

> Do no attempt to resolve container binding implementations such as config, session driver, logger inside the `hermes` config file. This is because those implementations are not yet bound to the container when the `hermes` config is loaded.

```
'middleware' => [
    // This won't work properly
    GuzzleHttp\Middleware::log(logs(), new GuzzleHttp\MessageFormatter),
],
```

> Instead of using middleware in config, consider [customizing the guzzle handler stack](#customizing-the-guzzle-handler-stack) if you needs container binding implementations.

### Customizing the guzzle handler stack

[](#customizing-the-guzzle-handler-stack)

Sometimes you may need complete control over how guzzle's [HandleStack](http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html#handlerstack) is configured for an existing channel. For example, you may want to add, remove or unshift a middleware for a given channel's handler stack.

To get started, define a `tap` array on the channel's configuration. The `tap` array should contain a list of classes that should have an opportunity to customize (or "tap" into) the handle stack instance after it is created:

```
'default' => [
    'tap' => [
        App\Http\Client\CustomizeHandlerStack::class,
    ],
],
```

Once you have configured the `tap` option on your channel, you're ready to define the class that will customize your `HandlerStack` instance. This class only needs a single method: `__invoke`, which receives an `GuzzleHttp\HandlerStack` instance.

```
