Guzzle 6 Adapter

An HTTPlug adapter for the Guzzle 6 HTTP client.


To install the Guzzle adapter, which will also install Guzzle itself (if it was not yet included in your project), run:

$ composer require php-http/guzzle6-adapter


Begin by creating a Guzzle client, passing any configuration parameters you like:

use GuzzleHttp\Client as GuzzleClient;

$config = [
    // Config params
$guzzle = new GuzzleClient($config);

Then create the adapter:

use Http\Adapter\Guzzle6\Client as GuzzleAdapter;

$adapter = new GuzzleAdapter($guzzle);

And use it to send synchronous requests:

use GuzzleHttp\Psr7\Request;

$request = new Request('GET', '');

// Returns a Psr\Http\Message\ResponseInterface
$response = $adapter->sendRequest($request);

Or send asynchronous ones:

use GuzzleHttp\Psr7\Request;

$request = new Request('GET', '');

// Returns a Http\Promise\Promise
$promise = $adapter->sendAsyncRequest(request);

Further reading

  • Use plugins to customize the way HTTP requests are sent and responses processed by following redirects, adding Authentication or Cookie headers and more.
  • Learn how you can decouple your code from any PSR-7 implementation by using the HTTP factories.
  • Read more about promises when using asynchronous requests.