Skip to content

[READ-ONLY] Make a Symfony HttpClient to return Guzzle promises

License

Notifications You must be signed in to change notification settings

manyou-io/promise-http-client

Repository files navigation

Make a Symfony HttpClient to return Guzzle promises

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.

About

[READ-ONLY] Make a Symfony HttpClient to return Guzzle promises

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages