bohan / promise-http-client
Make a Symfony HttpClient to return Guzzle promises
Installs: 8 424
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.2.5 || ^8.0
- guzzlehttp/promises: ^1.4
- psr/log: ^1.1
- symfony/http-client-contracts: ^1.0 || ^2.0
Requires (Dev)
- monolog/monolog: ^2.1
- phpunit/phpunit: ^8.5 || ^9.2
- symfony/http-client: ^5.1
- symfony/process: ^5.1
This package is auto-updated.
Last update: 2022-11-08 07:53:37 UTC
README
Install
composer require bohan/promise-http-client
If you don't have a symfony/http-client-implementation yet:
composer require symfony/http-client
Example usage
use Bohan\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.