Skip to content

Commit fa9580b

Browse files
committed
Merge pull request #67 from php-http/guzzle6-doc
Add Guzzle 6 adapter docs
2 parents 72aeedc + 3080bd1 commit fa9580b

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

Diff for: clients/guzzle6-adapter.rst

+54-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,54 @@
1-
Guzzle6 Adapter
2-
===============
1+
Guzzle 6 Adapter
2+
================
3+
4+
An HTTPlug adapter for the `Guzzle 6 HTTP client`_.
5+
6+
To install the Guzzle adapter, which will also install Guzzle itself (if it was
7+
not yet included in your project), run:
8+
9+
.. code-block:: bash
10+
11+
$ composer require php-http/guzzle6-adapter
12+
13+
Then begin by creating a Guzzle client, passing any configuration parameters you
14+
like::
15+
16+
use GuzzleHttp\Client as GuzzleClient;
17+
18+
$config = [
19+
// Config params
20+
];
21+
$guzzle = new GuzzleClientClient($config);
22+
23+
Then create the adapter::
24+
25+
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
26+
27+
$adapter = new GuzzleAdapter($guzzle);
28+
29+
And use it to send synchronous requests::
30+
31+
use GuzzleHttp\Psr7\Request;
32+
33+
$request = new Request('GET', 'http://httpbin.org');
34+
35+
// Returns a Psr\Http\Message\ResponseInterface
36+
$response = $adapter->sendRequest($request);
37+
38+
Or send asynchronous ones::
39+
40+
use GuzzleHttp\Psr7\Request;
41+
42+
$request = new Request('GET', 'http://httpbin.org');
43+
44+
// Returns a Http\Promise\Promise
45+
$promise = $adapter->sendAsyncRequest(request);
46+
47+
Further reading
48+
---------------
49+
50+
* Read more about :doc:`promises </components/promise>`.
51+
* Learn how you can decouple your code from any PSR-7 implementation (such as
52+
Guzzle’s above) by using a :ref:`message factory <message-factory>`.
53+
54+
.. _Guzzle 6 HTTP client: http://docs.guzzlephp.org/

0 commit comments

Comments
 (0)