{"id":19665899,"url":"https://github.com/amphp/http-client-psr7","last_synced_at":"2025-04-28T22:31:29.721Z","repository":{"id":42139409,"uuid":"264733782","full_name":"amphp/http-client-psr7","owner":"amphp","description":"PSR-7 adapter for amphp/http-client.","archived":false,"fork":false,"pushed_at":"2024-11-14T05:42:34.000Z","size":71,"stargazers_count":13,"open_issues_count":1,"forks_count":2,"subscribers_count":7,"default_branch":"1.x","last_synced_at":"2025-04-05T11:34:16.646Z","etag":null,"topics":["amphp","http-client","php","psr-7"],"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/amphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2020-05-17T18:44:30.000Z","updated_at":"2025-03-22T00:21:10.000Z","dependencies_parsed_at":"2024-08-12T13:03:22.027Z","dependency_job_id":null,"html_url":"https://github.com/amphp/http-client-psr7","commit_stats":{"total_commits":6,"total_committers":2,"mean_commits":3.0,"dds":"0.16666666666666663","last_synced_commit":"0928e41b1ec28222b6fa9a3913c30bddb890087c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amphp%2Fhttp-client-psr7","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amphp%2Fhttp-client-psr7/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amphp%2Fhttp-client-psr7/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amphp%2Fhttp-client-psr7/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amphp","download_url":"https://codeload.github.com/amphp/http-client-psr7/tar.gz/refs/heads/1.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251397603,"owners_count":21583041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["amphp","http-client","php","psr-7"],"created_at":"2024-11-11T16:25:23.666Z","updated_at":"2025-04-28T22:31:27.500Z","avatar_url":"https://github.com/amphp.png","language":"PHP","funding_links":[],"categories":["HTTP"],"sub_categories":["Client"],"readme":"# amphp/http-client-psr7\n\nAMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind.\nThis package provides an [PSR-7](https://www.php-fig.org/psr/psr-7/) adapter and [PSR-18](https://www.php-fig.org/psr/psr-18/) client as a plugin for [`amphp/http-client`](https://github.com/amphp/http-client).\n\n[![Latest Release](https://img.shields.io/github/release/amphp/http-client-psr7.svg?style=flat-square)](https://github.com/amphp/http-client-psr7/releases)\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/amphp/http-client-psr7/blob/1.x/LICENSE)\n\n## Installation\n\nThis package can be installed as a [Composer](https://getcomposer.org/) dependency.\n\n```bash\ncomposer require amphp/http-client-psr7\n```\n\n## Requirements\n\n- PHP 8.1+\n\n## Usage\n\nCreate `Amp\\Http\\Client\\Psr7\\PsrAdapter` instance to convert client requests and responses between native Amp and [PSR-7](https://www.php-fig.org/psr/psr-7/) formats. Adapter doesn't depend on any concrete PSR-7 implementation, so it requires [PSR-17](https://www.php-fig.org/psr/psr-17/) factory interfaces to create PSR-7 requests and responses.\n\nUse `Amp\\Http\\Client\\Psr7\\PsrHttpClient` as a drop-in implementation of a [PSR-18](https://www.php-fig.org/psr/psr-18/) `ClientInterface`.\n\n```php\n\u003c?php\n\nrequire 'vendor/autoload.php';\n\nuse Amp\\Http\\Client\\HttpClientBuilder;\nuse Amp\\Http\\Client\\Psr7\\PsrAdapter;\nuse Amp\\Http\\Client\\Psr7\\PsrHttpClient;\nuse Laminas\\Diactoros\\RequestFactory;\nuse Laminas\\Diactoros\\ResponseFactory;\n\n// Note the laminas/laminas-diactoros library is used only as an example.\n// You can use any library providing an implementation of PSR-17.\n\n// PSR-17 request factory\n$psrRequestFactory = new RequestFactory();\n// PSR-17 response factory\n$psrResponseFactory = new ResponseFactory();\n\n$psrAdapter = new PsrAdapter($psrRequestFactory, $psrResponseFactory);\n\n$ampHttpClient = HttpClientBuilder::buildDefault();\n$psrHttpClient = new PsrHttpClient($ampHttpClient, $psrAdapter);\n\n$request = $psrRequestFactory-\u003ecreateRequest('GET', 'https://google.com');\n\n// $response is a PSR-7 ResponseInterface instance.\n$response = $psrHttpClient-\u003esendRequest($request);\n```\n\nThere are few incompatibilities between Amp and PSR-7 implementations that may require special handling:\n\n- PSR-7 requests contain only one protocol version, but Amp requests can contain several versions. In this case the adapter checks if the protocol version list contains a version that is the current PSR-7 implementation default, otherwise it throws an exception. You may also set the protocol version explicitly using the optional argument of the `toPsrRequest()` method.\n- Amp responses contain a reference to the `Request` instance, but PSR-7 responses don't; so you need to provide a request instance explicitly.\n\n## Examples\n\nMore extensive code examples reside in the [`examples`](./examples) directory.\n\n## Versioning\n\n`amphp/http-client-psr7` follows the [semver](http://semver.org/) semantic versioning specification like all other `amphp` packages.\n\n## Security\n\nIf you discover any security related issues, please use the private security issue reporter instead of using the public issue tracker.\n\n## License\n\nThe MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famphp%2Fhttp-client-psr7","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famphp%2Fhttp-client-psr7","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famphp%2Fhttp-client-psr7/lists"}