PHPackages                             indigophp/http-adapter - 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. indigophp/http-adapter

Abandoned → [egeloen/http-adapter](/?search=egeloen%2Fhttp-adapter)ArchivedLibrary[HTTP &amp; Networking](/categories/http)

indigophp/http-adapter
======================

Provides adapters for common HTTP Client libraries

01711PHP

Since Oct 19Pushed 11y ago1 watchersCompare

[ Source](https://github.com/indigophp-archive/http-adapter)[ Packagist](https://packagist.org/packages/indigophp/http-adapter)[ RSS](/packages/indigophp-http-adapter/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Indigo HTTP Adapter
===================

[](#indigo-http-adapter)

[![Latest Version](https://camo.githubusercontent.com/88f4d4398f930fd3792e9ff02118328f4b35897fe504345adf97a2057d4f6a8b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f696e6469676f7068702f687474702d616461707465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/indigophp/http-adapter/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/8285321266312cfc7acd30b259bef3a9dff5dbf28bf4b28fbe999c283eb754c9/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f696e6469676f7068702f687474702d616461707465722f646576656c6f702e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/indigophp/http-adapter)[![Code Coverage](https://camo.githubusercontent.com/80eeadd814b4abbdfb77b0ca7a42f2f775ccc1a5576097b256b9470d57745f9c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f696e6469676f7068702f687474702d616461707465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/indigophp/http-adapter)[![Quality Score](https://camo.githubusercontent.com/406da043d7b5652cbfe1f70a441d61eee9755e07e054baa97c966275b11b5308/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f696e6469676f7068702f687474702d616461707465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/indigophp/http-adapter)[![HHVM Status](https://camo.githubusercontent.com/be3a9cec63f9b8118839f6ad3484135cec8cc3b574724df3741139b9dd2a8ac6/68747470733a2f2f696d672e736869656c64732e696f2f6868766d2f696e6469676f7068702f687474702d616461707465722e7376673f7374796c653d666c61742d737175617265)](http://hhvm.h4cc.de/package/indigophp/http-adapter)[![Total Downloads](https://camo.githubusercontent.com/8233a5550aed947ce626cdbb911be79a41b069de2ad139d031ff7c461016eb46/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e6469676f7068702f687474702d616461707465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/indigophp/http-adapter)

**Provides adapters for common HTTP Client libraries.**

Why an other HTTP library again?
--------------------------------

[](#why-an-other-http-library-again)

The proposed HTTP Message [PSR](https://github.com/php-fig/fig-standards/blob/master/proposed/http-message.md) is going to be great....but that won't let anyone create HTTP Client agnostic packages. For example you cannot typehint for a `ClientInterface`. You can only operate on the same messages. The PSR Meta also mentions adapter packages as a valid approach. There are many cool adapter packages out there, but all of them implement a simple logic based on the author's need. You can consider this package as a simple `Adapter` providing you full control over the common fetures of the implemented HTTP Client libraries. However, it must be noted that the specific features are out of scope. For example: if you need to use Guzzle specific feature, depend on it instead.

This package also provides a simple implementation of the latest PSR interfaces.

Install
-------

[](#install)

Via Composer

```
$ composer require indigophp/http-adapter
```

Usage
-----

[](#usage)

### Simple usage

[](#simple-usage)

You are free to directly use any adapters in your application.

```
use Indigo\Http\Adapter;

class MyAdapterAware
{
    /**
     * @var Adapter
     */
    private $adapter;

    public function __construct(Adapter $adapter)
    {
        $this->adapter = $adapter;
    }

    public function get()
    {
        $request = new Request;
        $request->setUrl('http://foo.com');

        return $this->adapter->send($request);
    }
}
```

You can also use the client class for the most common client usage. (Guzzle is only used as an example)

```
use GuzzleHttp\Client as GuzzleClient;
use Indigo\Http\Adapter\Guzzle4;
use Indigo\Http\Client;

$adapter = new Guzzle4(new GuzzleClient);
$client = new Client($adapter);

$client->get('http://foo.com');
```

### Advanced usage

[](#advanced-usage)

For testing you can use the `Mock` adapter.

```
use Indigo\Http\Adapter\Mock;
use Psr\Http\Message\RequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;

// ... your testing logic

// you can directly pass the Response object to the constructor
$adapter = new Mock(function(Request $request) {
    return new Response;
});

// Optionally
$adapter->setResponse(new Response);

// ... your testing logic
```

You can decorate your adapters with various decorators.

#### Event decorator

[](#event-decorator)

Event decorator emitts two events:

- Before (request)
- Complete (response)

Both events receive the `Adapter` and the `Request`. The `Complete` event contains the `Response` as well.

```
use Indigo\Http\Adapter\Event;
use Indigo\Http\Event;

$adapter = new Event($decoratedAdapter);

// Optionally
// $adapter->setEmitter($emitter);

$adapter->addListener('before', function(Event\Before $event) {
    $adapter = $event->getAdapter();
    $request = $event->getRequest();

    // ... do something with the adapter and the request
});

$adapter->addListener('complete', function(Event\Complete $event) {
    $adapter = $event->getAdapter();
    $request = $event->getRequest();
    $response = $event->getResponse();

    // ... do something with the adapter, request and the response
});
```

You can also use `Subscriber`s with the `Event` adapter.

```
use Indigo\Http\Adapter\Event;
use Indigo\Http\Subscriber\Auth;

$adapter = new Event($decoratedAdapter);

// This will always attach authentication data to your requests
$adapter->addSubscriber(new Auth('username', 'password', Auth::BASIC));
```

Currently [league/event](http://event.thephpleague.com) is used as event backend.

#### Cache decorator

[](#cache-decorator)

You can use a local cache for returned `Response`s. Based on cached items you can send `Request`s to the server with `If-Modified-Since` and `If-None-Match` (`ETag` header required in response) headers. If the server return with 304 status then the cached item is returned, otherwise it gets cached for future.

```
use Indigo\Http\Adapter\Cache;

$adapter = new Cache($decoratedAdapter);

// Optionally
// $adapter->setPool($pool);

// Status: 200 OK
$response = $adapter->send($request);

// Status: 304 Not Modified
// Returned from cache
$response = $adapter->send($request);
```

Currently [Stash](http://stashphp.com) is used as cache backend.

### Exceptions

[](#exceptions)

There are two main type of exceptions:

- `AdapterException`: Thrown when some sort of adapter problem occurs.
- `RequestException`: Thrown if the response itself is an error response (4xx, 5xx) or the request cannot be completed (no response returned).

Testing
-------

[](#testing)

```
$ phpspec run
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Márk Sági-Kazár](https://github.com/sagikazarmark)
- [All Contributors](https://github.com/indigophp/http-adapter/contributors)

Inspired by
-----------

[](#inspired-by)

- Guzzle
- fXmlRpc

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e4e105cea62b616d4cb376b08a849b6a428f646998537de150d16a8eb537b90?d=identicon)[mark.sagikazar](/maintainers/mark.sagikazar)

![](https://www.gravatar.com/avatar/1585b5a08e138e348f5b646231d0f16cb2eae06501fb9462bbc97a794d4de84a?d=identicon)[TamasBarta](/maintainers/TamasBarta)

---

Top Contributors

[![sagikazarmark](https://avatars.githubusercontent.com/u/1226384?v=4)](https://github.com/sagikazarmark "sagikazarmark (86 commits)")

### Embed Badge

![Health badge](/badges/indigophp-http-adapter/health.svg)

```
[![Health](https://phpackages.com/badges/indigophp-http-adapter/health.svg)](https://phpackages.com/packages/indigophp-http-adapter)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M317](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M292](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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