manyou / promise-http-client
Make a Symfony HttpClient to return Guzzle promises
dev-main / 0.1.x-dev
2024-03-22 07:36 UTC
Requires
- php: >=8.1
- guzzlehttp/promises: ^1.4|^2.0
- psr/log: ^2.0|^3.0
- symfony/http-client-contracts: ^3.0
- symfony/http-client-implementation: ^3.0
Requires (Dev)
- symfony/http-client: ^6.4|^7.0
- symfony/process: ^6.4|^7.0
This package is auto-updated.
Last update: 2024-11-22 09:16:43 UTC
README
Install
composer require manyou/promise-http-client
If you don't have a symfony/http-client-implementation yet:
composer require symfony/http-client
Example usage
use Manyou\PromiseHttpClient\PromiseHttpClient; use Symfony\Component\HttpClient\HttpClient; use Symfony\Contracts\HttpClient\ResponseInterface; $client = new PromiseHttpClient(HttpClient::create()); $promise = $client->request('GET', 'https://httpbin.org/status/429')->then(function (ResponseInterface $response) use ($client) { if ($response->getStatusCode() < 300) { return $response; } return $client->request('GET', 'https://httpbin.org/get'); }); /** @var ResponseInterface $response */ $response = $promise->wait(); echo $response->getStatusCode(); // 200
Credits
Most code of
comes from the HttplugClient of the Symfony HttpClient component.