Skip to content

Commit

Permalink
Adding docs for Guzzle7 (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Sep 17, 2020
1 parent e5c1d9a commit a1c559c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
9 changes: 9 additions & 0 deletions clients.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface and forwarding the calls to an HTTP client not implementing the interf
clients/cakephp-adapter
clients/guzzle5-adapter
clients/guzzle6-adapter
clients/guzzle7-adapter
clients/react-adapter
clients/zend-adapter

Expand All @@ -38,6 +39,7 @@ interface and forwarding the calls to an HTTP client not implementing the interf
"``php-http/cakephp-adapter``", "Adapter", ":doc:`Docs </clients/cakephp-adapter>`, `Repo <https://github.com/php-http/cakephp-adapter>`__", "|cakephp_version| |cakephp_downloads| "
"``php-http/guzzle5-adapter``", "Adapter", ":doc:`Docs </clients/guzzle5-adapter>`, `Repo <https://github.com/php-http/guzzle5-adapter>`__", "|guzzle5_version| |guzzle5_downloads| "
"``php-http/guzzle6-adapter``", "Adapter", ":doc:`Docs </clients/guzzle6-adapter>`, `Repo <https://github.com/php-http/guzzle6-adapter>`__", "|guzzle6_version| |guzzle6_downloads| "
"``php-http/guzzle7-adapter``", "Adapter", ":doc:`Docs </clients/guzzle7-adapter>`, `Repo <https://github.com/php-http/guzzle7-adapter>`__", "|guzzle7_version| |guzzle7_downloads| "
"``php-http/react-adapter``", "Adapter", ":doc:`Docs </clients/react-adapter>`, `Repo <https://github.com/php-http/react-adapter>`__", "|react_version| |react_downloads| "
"``php-http/zend-adapter``", "Adapter", ":doc:`Docs </clients/zend-adapter>`, `Repo <https://github.com/php-http/zend-adapter>`__", "|zend_version| |zend_downloads| "

Expand Down Expand Up @@ -120,6 +122,13 @@ HTTPlug use the ``provide`` section to tell composer that they do provide the cl
:target: https://github.com/php-http/guzzle6-adapter/releases
:alt: Latest Version

.. |guzzle7_downloads| image:: https://img.shields.io/packagist/dt/php-http/guzzle7-adapter.svg?style=flat-square
:target: https://packagist.org/packages/php-http/guzzle7-adapter
:alt: Total Downloads
.. |guzzle7_version| image:: https://img.shields.io/github/release/php-http/guzzle7-adapter.svg?style=flat-square
:target: https://github.com/php-http/guzzle7-adapter/releases
:alt: Latest Version

.. |react_downloads| image:: https://img.shields.io/packagist/dt/php-http/react-adapter.svg?style=flat-square
:target: https://packagist.org/packages/php-http/react-adapter
:alt: Total Downloads
Expand Down
4 changes: 2 additions & 2 deletions clients/guzzle6-adapter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ to the client::
$guzzle = new GuzzleClient($config);
// ...
$adapter = new GuzzleAdapter($guzzle);

If you pass a Guzzle instance to the adapter, make sure to configure Guzzle to not throw exceptions on HTTP error status codes, or this adapter will violate PSR-18.

And use it to send synchronous requests::
Expand All @@ -65,4 +65,4 @@ Or send asynchronous ones::

.. include:: includes/further-reading-async.inc

.. _Guzzle 6 HTTP client: http://docs.guzzlephp.org/
.. _Guzzle 6 HTTP client: http://docs.guzzlephp.org/en/6.5/
70 changes: 70 additions & 0 deletions clients/guzzle7-adapter.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Guzzle 7 Adapter
================

An HTTPlug adapter for the `Guzzle 7 HTTP client`_. Guzzle 7 supports PSR-18
out of the box. This adapter makes sense if you want to use HTTPlug async interface or to use
Guzzle 7 with a library that did not upgrade to PSR-18 yet and depends on ``php-http/client-implementation``.

Installation
------------

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

.. code-block:: bash
$ composer require php-http/guzzle7-adapter
Usage
-----

To create a Guzzle7 adapter you should use the `createWithConfig()` function. It will let you to pass Guzzle configuration
to the client::

use Http\Adapter\Guzzle7\Client as GuzzleAdapter;

$config = [
'timeout' => 2,
'handler' => //...
// ...
];
$adapter = GuzzleAdapter::createWithConfig($config);

.. note::

If you want even more control over your Guzzle object, you may give a Guzzle client as first argument to the adapter's
constructor::

use GuzzleHttp\Client as GuzzleClient;
use Http\Adapter\Guzzle7\Client as GuzzleAdapter;

$config = ['timeout' => 5];
// ...
$guzzle = new GuzzleClient($config);
// ...
$adapter = new GuzzleAdapter($guzzle);

If you pass a Guzzle instance to the adapter, make sure to configure Guzzle to not throw exceptions on HTTP error status codes, or this adapter will violate PSR-18.

And use it to send synchronous requests::

use GuzzleHttp\Psr7\Request;

$request = new Request('GET', 'http://httpbin.org');

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

Or send asynchronous ones::

use GuzzleHttp\Psr7\Request;

$request = new Request('GET', 'http://httpbin.org');

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


.. include:: includes/further-reading-async.inc

.. _Guzzle 7 HTTP client: http://docs.guzzlephp.org/en/7.0/

0 comments on commit a1c559c

Please sign in to comment.