PHPackages                             http-interop/http-factory-discovery - 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. http-interop/http-factory-discovery

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

http-interop/http-factory-discovery
===================================

Utility to locate available HTTP factory implementations

1.6.0(2y ago)5215.5k↓13.3%2[1 issues](https://github.com/http-interop/http-factory-discovery/issues)9MITPHPPHP &gt;=7.1

Since Oct 11Pushed 2y ago1 watchersCompare

[ Source](https://github.com/http-interop/http-factory-discovery)[ Packagist](https://packagist.org/packages/http-interop/http-factory-discovery)[ Docs](https://github.com/http-interop/http-factory-discovery)[ RSS](/packages/http-interop-http-factory-discovery/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (9)Used By (9)

HTTP Discovery
==============

[](#http-discovery)

[![Latest Stable Version](https://camo.githubusercontent.com/574d9ad9fe9cb3b093272a196978c36fdfd4358816f5a7d107243c579a24a750/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f687474702d696e7465726f702f687474702d666163746f72792d646973636f766572792e737667)](https://packagist.org/packages/http-interop/http-factory-discovery)[![License](https://camo.githubusercontent.com/6db26e87660d4551a46c58050a510ef7f2eb703db5eedbfa0c9630223bcfdc8c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f687474702d696e7465726f702f687474702d666163746f72792d646973636f766572792e737667)](https://github.com/http-interop/http-factory-discovery/blob/master/LICENSE)[![Build Status](https://camo.githubusercontent.com/a02909bf682490da747524d159da29353e9d10e1d1f02e4c83b74ff449853ae7/68747470733a2f2f7472617669732d63692e6f72672f687474702d696e7465726f702f687474702d666163746f72792d646973636f766572792e737667)](https://travis-ci.org/http-interop/http-factory-discovery)[![Code Coverage](https://camo.githubusercontent.com/ea921a5473c7129fe5409ddf8b25d112a46433f822dbe0db9a4b4e6ddc829021/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f687474702d696e7465726f702f687474702d666163746f72792d646973636f766572792f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/http-interop/http-factory-discovery/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6cb1cfbc934f5b1b2ed719a519cfb850e4db6a42a2756e3f6819ba9be8bd67b4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f687474702d696e7465726f702f687474702d666163746f72792d646973636f766572792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/http-interop/http-factory-discovery/?branch=master)

Package for automatic discovery of available implementations providing HTTP functionality. Allows for fast switching between different implementations with minimal effort.

Automatic discovery of [HTTP Factories](https://www.php-fig.org/psr/psr-17/) and [HTTP Clients](https://www.php-fig.org/psr/psr-18/) is supported.

By default, the following implementations can be discovered:

HTTP Factory
------------

[](#http-factory)

- [Guzzle](https://github.com/http-interop/http-factory-guzzle)
- [Zend Diactoros](https://github.com/http-interop/http-factory-diactoros)
- [Slim](https://github.com/http-interop/http-factory-slim)
- [Nyholm](https://github.com/Nyholm/psr7)
- [Sunrise](https://github.com/sunrise-php/http-factory)

HTTP Client
-----------

[](#http-client)

- [Guzzle](https://github.com/php-http/guzzle6-adapter)

Additional implementations [can be registered](#registering-additional-implementations).

Install
-------

[](#install)

```
composer require http-interop/http-factory-discovery

```

Usage
-----

[](#usage)

### HTTP Factory

[](#http-factory-1)

```
use Http\Factory\Discovery\HttpFactory;

/** @var \Psr\Http\Message\RequestFactoryInterface */
$requestFactory = HttpFactory::requestFactory();

/** @var \Psr\Http\Message\ResponseFactoryInterface */
$responseFactory = HttpFactory::responseFactory();

/** @var \Psr\Http\Message\ServerRequestFactoryInterface */
$serverRequestFactory = HttpFactory::serverRequestFactory();

/** @var \Psr\Http\Message\StreamFactoryInterface */
$streamFactory = HttpFactory::streamFactory();

/** @var \Psr\Http\Message\UriFactoryInterface */
$uriFactory = HttpFactory::uriFactory();

/** @var \Psr\Http\Message\UploadedFileFactoryInterface */
$uploadedFileFactory = HttpFactory::uploadedFileFactory();
```

### HTTP Client

[](#http-client-1)

```
use Http\Factory\Discovery\HttpClient;

/** @var \Psr\Http\Client\ClientInterface */
$client = HttpClient::client();
```

### Best Practices

[](#best-practices)

Because this package acts as a [service locator](https://en.wikipedia.org/wiki/Service_locator_pattern) it should be used to supplement [dependency injection](https://en.wikipedia.org/wiki/Dependency_injection).

#### HTTP Factory

[](#http-factory-2)

A prime example for using HTTP Factories would be when writing [PSR-15 middleware](https://www.php-fig.org/psr/psr-15/):

```
namespace Acme\Middleware;

use Http\Factory\Discovery\HttpFactory;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface as Handler;

class CatchErrors extends MiddlewareInterface
{
    /** @var ResponseFactoryInterface */
    private $responseFactory;

    /** @var StreamFactoryInterface */
    private $streamFactory;

    public function __construct(
        ResponseFactoryInterface $responseFactory = null,
        StreamFactoryInterface $streamFactory = null
    ) {
        $this->responseFactory = $responseFactory ?? HttpFactory::responseFactory();
        $this->streamFactory = $streamFactory ?? HttpFactory::streamFactory();
    }

    public function process(Request $request, Handler $handler): Response
    {
        try {
            return $handler->handle($request);
        } catch (\Throwable $error) {
            $stream = $this->streamFactory->createStream($e->getMessage());

            $response = $this->responseFactory->createResponse(500);
            $response = $response->withHeader('content-type', 'text/plain');
            $response = $response->withBody($stream);

            return $response;
        }
    }
}
```

#### HTTP Client

[](#http-client-2)

An example for using both HTTP Client and HTTP Factories would be when writing functionality sending HTTP requests:

```
namespace Acme;

use Http\Factory\Discovery\HttpClient;
use Http\Factory\Discovery\HttpFactory;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;

class Api
{
    /** @var ClientInterface */
    private $client;

    /** @var RequestFactoryInterface */
    private $requestFactory;

    public function __construct(
        ClientInterface $client = null,
        RequestFactoryInterface $requestFactory = null
    ) {
        $this->client = $client ?? HttpClient::client();
        $this->requestFactory = $requestFactory ?? HttpFactory::requestFactory();
    }

    public function query(): string
    {
        $request = $this->requestFactory->createRequest('GET', 'http://acme.com/api');

        return $this->client->sendRequest($request)->getBody()->getContents();
    }
}
```

### Registering Additional Implementations

[](#registering-additional-implementations)

Additional implementations can be registered:

#### HTTP Factory

[](#http-factory-3)

```
use Acme\RequestFactory;
use Http\Factory\Discovery\FactoryLocator;
use Psr\Http\Message\RequestFactoryInterface;

FactoryLocator::register(RequestFactoryInterface::class, RequestFactory::class);
```

#### HTTP Client

[](#http-client-3)

```
use Acme\Client;
use Http\Factory\Discovery\ClientLocator;
use Psr\Http\Client\ClientInterface;

ClientLocator::register(ClientInterface::class, Client::class);
```

Implementations can also be unregistered, if you prefer not to use them:

#### HTTP Factory

[](#http-factory-4)

```
use Http\Factory\Discovery\FactoryLocator;
use Http\Factory\Guzzle\UriFactory;
use Psr\Http\Message\UriFactoryInterface;

FactoryLocator::unregister(UriFactoryInterface::class, UriFactory::class);
```

#### HTTP Client

[](#http-client-4)

```
use Http\Factory\Discovery\ClientLocator;
use Http\Adapter\Guzzle6\Client;
use Psr\Http\Client\ClientInterface;

ClientLocator::unregister(ClientInterface::class, Client::class);
```

### Clearing Cache

[](#clearing-cache)

The cache of discovered implementations can be cleared:

#### HTTP Factory

[](#http-factory-5)

```
use Http\Factory\Discovery\HttpFactory;
use Psr\Http\Message\UriFactoryInterface;

// Clear a single interface
HttpFactory::clearCache(UriFactoryInterface::class);

// Clear all interfaces
HttpFactory::clearCache();
```

#### HTTP Client

[](#http-client-5)

```
use Http\Factory\Discovery\HttpClient;
use Psr\Http\Client\ClientInterface;

// Clear a single interface
HttpClient::clearCache(ClientInterface::class);

// Clear all interfaces
HttpClient::clearCache();
```

*Note: Cache is automatically cleared when `FactoryLocator::unregister()` or `ClientLocator::unregister()` is called.*

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 68% 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 ~264 days

Recently: every ~462 days

Total

8

Last Release

924d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/38203?v=4)[Woody Gilk](/maintainers/shadowhand)[@shadowhand](https://github.com/shadowhand)

---

Top Contributors

[![shadowhand](https://avatars.githubusercontent.com/u/38203?v=4)](https://github.com/shadowhand "shadowhand (17 commits)")[![Stadly](https://avatars.githubusercontent.com/u/7263579?v=4)](https://github.com/Stadly "Stadly (7 commits)")[![fenric](https://avatars.githubusercontent.com/u/2872934?v=4)](https://github.com/fenric "fenric (1 commits)")

---

Tags

discoveryhttp-factorypsr-17psr-7service-locatorhttppsr-7clientfactorypsr-17psr-18psr7discoverypsr17psr18

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/http-interop-http-factory-discovery/health.svg)

```
[![Health](https://phpackages.com/badges/http-interop-http-factory-discovery/health.svg)](https://phpackages.com/packages/http-interop-http-factory-discovery)
```

###  Alternatives

[php-http/discovery

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

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

The Official Vultr API PHP Wrapper.

2243.9k1](/packages/vultr-vultr-php)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[chillerlan/php-httpinterface

A PSR-7/17/18 http message/client implementation

1417.1k5](/packages/chillerlan-php-httpinterface)[elastic/transport

HTTP transport PHP library for Elastic products

2020.6M7](/packages/elastic-transport)[pdeans/http

PSR-7 cURL HTTP client with support for PSR-17 HTTP factories.

1466.2k3](/packages/pdeans-http)

PHPackages © 2026

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