-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from php-http/guzzle6-doc
Add Guzzle 6 adapter docs
- Loading branch information
Showing
1 changed file
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,54 @@ | ||
Guzzle6 Adapter | ||
=============== | ||
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: | ||
|
||
.. code-block:: bash | ||
$ composer require php-http/guzzle6-adapter | ||
Then begin by creating a Guzzle client, passing any configuration parameters you | ||
like:: | ||
|
||
use GuzzleHttp\Client as GuzzleClient; | ||
|
||
$config = [ | ||
// Config params | ||
]; | ||
$guzzle = new GuzzleClientClient($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', '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); | ||
|
||
Further reading | ||
--------------- | ||
|
||
* Read more about :doc:`promises </components/promise>`. | ||
* Learn how you can decouple your code from any PSR-7 implementation (such as | ||
Guzzle’s above) by using a :ref:`message factory <message-factory>`. | ||
|
||
.. _Guzzle 6 HTTP client: http://docs.guzzlephp.org/ |