-
Notifications
You must be signed in to change notification settings - Fork 56
Adding docs for Guzzle7 #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
Guzzle 7 Adapter | ||
================ | ||
|
||
An HTTPlug adapter for the `Guzzle 7 HTTP client`_. Guzzle 7 will support PSR-18 | ||
out of the box. This adapter makes sense if you want to use HTTPlug async interface. | ||
Nyholm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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/ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.