Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amphp/http-client-psr7
PSR-7 adapter for amphp/http-client.
https://github.com/amphp/http-client-psr7
amphp http-client php psr-7
Last synced: about 2 months ago
JSON representation
PSR-7 adapter for amphp/http-client.
- Host: GitHub
- URL: https://github.com/amphp/http-client-psr7
- Owner: amphp
- License: mit
- Created: 2020-05-17T18:44:30.000Z (over 4 years ago)
- Default Branch: 1.x
- Last Pushed: 2024-09-04T00:27:42.000Z (4 months ago)
- Last Synced: 2024-10-03T08:47:48.592Z (3 months ago)
- Topics: amphp, http-client, php, psr-7
- Language: PHP
- Size: 68.4 KB
- Stars: 10
- Watchers: 8
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# amphp/http-client-psr7
AMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind.
This 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).[![Latest Release](https://img.shields.io/github/release/amphp/http-client-psr7.svg?style=flat-square)](https://github.com/amphp/http-client-psr7/releases)
[![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)## Installation
This package can be installed as a [Composer](https://getcomposer.org/) dependency.
```bash
composer require amphp/http-client-psr7
```## Requirements
- PHP 8.1+
## Usage
Create `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.
Use `Amp\Http\Client\Psr7\PsrHttpClient` as a drop-in implementation of a [PSR-18](https://www.php-fig.org/psr/psr-18/) `ClientInterface`.
```php
createRequest('GET', 'https://google.com');// $response is a PSR-7 ResponseInterface instance.
$response = $psrHttpClient->sendRequest($request);
```There are few incompatibilities between Amp and PSR-7 implementations that may require special handling:
- 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.
- Amp responses contain a reference to the `Request` instance, but PSR-7 responses don't; so you need to provide a request instance explicitly.## Examples
More extensive code examples reside in the [`examples`](./examples) directory.
## Versioning
`amphp/http-client-psr7` follows the [semver](http://semver.org/) semantic versioning specification like all other `amphp` packages.
## Security
If you discover any security related issues, please use the private security issue reporter instead of using the public issue tracker.
## License
The MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information.