{"id":37234661,"url":"https://github.com/http-interop/http-factory-discovery","last_synced_at":"2026-01-15T04:00:12.358Z","repository":{"id":56986505,"uuid":"152603069","full_name":"http-interop/http-factory-discovery","owner":"http-interop","description":"Utility to discover available HTTP factory implementations","archived":false,"fork":false,"pushed_at":"2023-11-06T13:40:58.000Z","size":32,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-29T21:50:26.475Z","etag":null,"topics":["discovery","http-factory","psr-17","psr-7","service-locator"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/http-interop.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-11T14:14:53.000Z","updated_at":"2024-10-19T21:43:06.000Z","dependencies_parsed_at":"2024-06-18T22:36:09.862Z","dependency_job_id":"c8323f5a-785b-4c58-adbd-7f75f4df8fb7","html_url":"https://github.com/http-interop/http-factory-discovery","commit_stats":{"total_commits":20,"total_committers":3,"mean_commits":6.666666666666667,"dds":0.4,"last_synced_commit":"e49a39aeb1c4f9187d3a1d3b31f1ad734f7a568f"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/http-interop/http-factory-discovery","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http-interop%2Fhttp-factory-discovery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http-interop%2Fhttp-factory-discovery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http-interop%2Fhttp-factory-discovery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http-interop%2Fhttp-factory-discovery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/http-interop","download_url":"https://codeload.github.com/http-interop/http-factory-discovery/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http-interop%2Fhttp-factory-discovery/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28419764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discovery","http-factory","psr-17","psr-7","service-locator"],"created_at":"2026-01-15T04:00:11.509Z","updated_at":"2026-01-15T04:00:12.344Z","avatar_url":"https://github.com/http-interop.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTTP Discovery\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/http-interop/http-factory-discovery.svg)](https://packagist.org/packages/http-interop/http-factory-discovery)\n[![License](https://img.shields.io/packagist/l/http-interop/http-factory-discovery.svg)](https://github.com/http-interop/http-factory-discovery/blob/master/LICENSE)\n[![Build Status](https://travis-ci.org/http-interop/http-factory-discovery.svg)](https://travis-ci.org/http-interop/http-factory-discovery)\n[![Code Coverage](https://scrutinizer-ci.com/g/http-interop/http-factory-discovery/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/http-interop/http-factory-discovery/?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/http-interop/http-factory-discovery/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/http-interop/http-factory-discovery/?branch=master)\n\nPackage for automatic discovery of available implementations providing HTTP\nfunctionality. Allows for fast switching between different implementations with\nminimal effort.\n\nAutomatic discovery of [HTTP Factories][psr17] and [HTTP Clients][psr18] is\nsupported.\n\nBy default, the following implementations can be discovered:\n\n## HTTP Factory\n\n- [Guzzle](https://github.com/http-interop/http-factory-guzzle)\n- [Zend Diactoros](https://github.com/http-interop/http-factory-diactoros)\n- [Slim](https://github.com/http-interop/http-factory-slim)\n- [Nyholm](https://github.com/Nyholm/psr7)\n- [Sunrise](https://github.com/sunrise-php/http-factory)\n\n## HTTP Client\n\n- [Guzzle](https://github.com/php-http/guzzle6-adapter)\n\nAdditional implementations [can be registered][add-implementations].\n\n[add-implementations]: #registering-additional-implementations\n[psr17]: https://www.php-fig.org/psr/psr-17/\n[psr18]: https://www.php-fig.org/psr/psr-18/\n\n## Install\n\n```\ncomposer require http-interop/http-factory-discovery\n```\n\n## Usage\n\n### HTTP Factory\n\n```php\nuse Http\\Factory\\Discovery\\HttpFactory;\n\n/** @var \\Psr\\Http\\Message\\RequestFactoryInterface */\n$requestFactory = HttpFactory::requestFactory();\n\n/** @var \\Psr\\Http\\Message\\ResponseFactoryInterface */\n$responseFactory = HttpFactory::responseFactory();\n\n/** @var \\Psr\\Http\\Message\\ServerRequestFactoryInterface */\n$serverRequestFactory = HttpFactory::serverRequestFactory();\n\n/** @var \\Psr\\Http\\Message\\StreamFactoryInterface */\n$streamFactory = HttpFactory::streamFactory();\n\n/** @var \\Psr\\Http\\Message\\UriFactoryInterface */\n$uriFactory = HttpFactory::uriFactory();\n\n/** @var \\Psr\\Http\\Message\\UploadedFileFactoryInterface */\n$uploadedFileFactory = HttpFactory::uploadedFileFactory();\n```\n\n### HTTP Client\n\n```php\nuse Http\\Factory\\Discovery\\HttpClient;\n\n/** @var \\Psr\\Http\\Client\\ClientInterface */\n$client = HttpClient::client();\n```\n\n### Best Practices\n\nBecause this package acts as a [service locator][service-locator] it should be\nused to supplement [dependency injection][dependency-injection].\n\n#### HTTP Factory\n\nA prime example for using HTTP Factories would be when writing\n[PSR-15 middleware][psr15]:\n\n```php\nnamespace Acme\\Middleware;\n\nuse Http\\Factory\\Discovery\\HttpFactory;\nuse Psr\\Http\\Message\\ResponseFactoryInterface;\nuse Psr\\Http\\Message\\ResponseInterface as Response;\nuse Psr\\Http\\Message\\ServerRequestInterface as Request;\nuse Psr\\Http\\Message\\StreamFactoryInterface;\nuse Psr\\Http\\Server\\MiddlewareInterface;\nuse Psr\\Http\\Server\\RequestHandlerInterface as Handler;\n\nclass CatchErrors extends MiddlewareInterface\n{\n    /** @var ResponseFactoryInterface */\n    private $responseFactory;\n\n    /** @var StreamFactoryInterface */\n    private $streamFactory;\n\n    public function __construct(\n        ResponseFactoryInterface $responseFactory = null,\n        StreamFactoryInterface $streamFactory = null\n    ) {\n        $this-\u003eresponseFactory = $responseFactory ?? HttpFactory::responseFactory();\n        $this-\u003estreamFactory = $streamFactory ?? HttpFactory::streamFactory();\n    }\n\n    public function process(Request $request, Handler $handler): Response\n    {\n        try {\n            return $handler-\u003ehandle($request);\n        } catch (\\Throwable $error) {\n            $stream = $this-\u003estreamFactory-\u003ecreateStream($e-\u003egetMessage());\n\n            $response = $this-\u003eresponseFactory-\u003ecreateResponse(500);\n            $response = $response-\u003ewithHeader('content-type', 'text/plain');\n            $response = $response-\u003ewithBody($stream);\n\n            return $response;\n        }\n    }\n}\n\n```\n[service-locator]: https://en.wikipedia.org/wiki/Service_locator_pattern\n[dependency-injection]: https://en.wikipedia.org/wiki/Dependency_injection\n[psr15]: https://www.php-fig.org/psr/psr-15/\n\n#### HTTP Client\n\nAn example for using both HTTP Client and HTTP Factories would be when writing\nfunctionality sending HTTP requests:\n\n```php\nnamespace Acme;\n\nuse Http\\Factory\\Discovery\\HttpClient;\nuse Http\\Factory\\Discovery\\HttpFactory;\nuse Psr\\Http\\Client\\ClientInterface;\nuse Psr\\Http\\Message\\RequestFactoryInterface;\n\nclass Api\n{\n    /** @var ClientInterface */\n    private $client;\n\n    /** @var RequestFactoryInterface */\n    private $requestFactory;\n\n    public function __construct(\n        ClientInterface $client = null,\n        RequestFactoryInterface $requestFactory = null\n    ) {\n        $this-\u003eclient = $client ?? HttpClient::client();\n        $this-\u003erequestFactory = $requestFactory ?? HttpFactory::requestFactory();\n    }\n\n    public function query(): string\n    {\n        $request = $this-\u003erequestFactory-\u003ecreateRequest('GET', 'http://acme.com/api');\n\n        return $this-\u003eclient-\u003esendRequest($request)-\u003egetBody()-\u003egetContents();\n    }\n}\n\n```\n\n### Registering Additional Implementations\n\nAdditional implementations can be registered:\n\n#### HTTP Factory\n\n```php\nuse Acme\\RequestFactory;\nuse Http\\Factory\\Discovery\\FactoryLocator;\nuse Psr\\Http\\Message\\RequestFactoryInterface;\n\nFactoryLocator::register(RequestFactoryInterface::class, RequestFactory::class);\n```\n\n#### HTTP Client\n\n```php\nuse Acme\\Client;\nuse Http\\Factory\\Discovery\\ClientLocator;\nuse Psr\\Http\\Client\\ClientInterface;\n\nClientLocator::register(ClientInterface::class, Client::class);\n```\n\nImplementations can also be unregistered, if you prefer not to use them:\n\n#### HTTP Factory\n\n```php\nuse Http\\Factory\\Discovery\\FactoryLocator;\nuse Http\\Factory\\Guzzle\\UriFactory;\nuse Psr\\Http\\Message\\UriFactoryInterface;\n\nFactoryLocator::unregister(UriFactoryInterface::class, UriFactory::class);\n```\n\n#### HTTP Client\n\n```php\nuse Http\\Factory\\Discovery\\ClientLocator;\nuse Http\\Adapter\\Guzzle6\\Client;\nuse Psr\\Http\\Client\\ClientInterface;\n\nClientLocator::unregister(ClientInterface::class, Client::class);\n```\n\n### Clearing Cache\n\nThe cache of discovered implementations can be cleared:\n\n#### HTTP Factory\n\n```php\nuse Http\\Factory\\Discovery\\HttpFactory;\nuse Psr\\Http\\Message\\UriFactoryInterface;\n\n// Clear a single interface\nHttpFactory::clearCache(UriFactoryInterface::class);\n\n// Clear all interfaces\nHttpFactory::clearCache();\n```\n\n#### HTTP Client\n\n```php\nuse Http\\Factory\\Discovery\\HttpClient;\nuse Psr\\Http\\Client\\ClientInterface;\n\n// Clear a single interface\nHttpClient::clearCache(ClientInterface::class);\n\n// Clear all interfaces\nHttpClient::clearCache();\n```\n\n_Note: Cache is automatically cleared when `FactoryLocator::unregister()` or\n`ClientLocator::unregister()` is called._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttp-interop%2Fhttp-factory-discovery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhttp-interop%2Fhttp-factory-discovery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttp-interop%2Fhttp-factory-discovery/lists"}