-
Notifications
You must be signed in to change notification settings - Fork 56
Create the React adapter documentation #83
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 all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,81 @@ | ||
React Adapter | ||
============= | ||
|
||
An HTTPlug adapter for the `React Http client`_. | ||
|
||
Installation | ||
------------ | ||
|
||
Use Composer_ to install the React adapter. It will also install React as it's a | ||
dependency. | ||
|
||
.. code-block:: bash | ||
|
||
$ composer require php-http/react-adapter | ||
|
||
.. include:: includes/install-message-factory.inc | ||
|
||
.. include:: includes/install-discovery.inc | ||
|
||
Usage | ||
----- | ||
|
||
The React client adapter needs a :ref:`message factory <message-factory>` in | ||
order to to work:: | ||
|
||
use Http\Adapter\React\Client; | ||
|
||
$client = new Client($messageFactory); | ||
|
||
For simplicity, all required objects are instantiated automatically if not | ||
explicitly specified: | ||
|
||
:React\EventLoop\LoopInterface: The event loop used inside the React engine. | ||
:React\HttpClient\Client: The HTTP client instance that must be adapted. | ||
|
||
If you need more control on the React instances, you can inject them during | ||
initialization:: | ||
|
||
use Http\Adapter\React\Client; | ||
|
||
$eventLoop = React\EventLoop\Factory::create(); | ||
$dnsResolverFactory = new React\Dns\Resolver\Factory(); | ||
$dnsResolver = $dnsResolverFactory->createCached('8.8.8.8', $loop); | ||
|
||
$factory = new React\HttpClient\Factory(); | ||
$reactHttp = $factory->create($loop, $dnsResolver); | ||
|
||
$adapter = new Client($messageFactory, $eventLoop, $reactHttp); | ||
|
||
If you choose to inject a custom React HTTP client, you must inject the loop | ||
used during its construction. But if you already use an EventLoop inside your | ||
code, you can inject only this object. | ||
|
||
You can also use a ``ReactFactory`` in order to initialize React instances:: | ||
|
||
use Http\Adapter\React\ReactFactory; | ||
|
||
$eventLoop = ReactFactory::buildEventLoop(); | ||
$reactHttp = ReactFactory::buildHttpClient($eventLoop); | ||
|
||
Then you can use the adapter 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 | ||
|
||
.. _React HTTP client: https://github.com/reactphp/http-client |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all required objects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also fixed it !