|
1 | | -Introduction to HTTPlug |
2 | | -======================= |
| 1 | +HTTPlug: HTTP client abstraction |
| 2 | +================================ |
3 | 3 |
|
4 | | -HTTPlug implementations |
5 | | ------------------------ |
| 4 | +HTTPlug allows you to write reusable libraries and applications that need |
| 5 | +an HTTP client without binding to a specific implementation. |
| 6 | +When all packages used in an application only specify HTTPlug, |
| 7 | +the application developers can choose the client that best fits their project |
| 8 | +and use the same client with all packages. |
| 9 | + |
| 10 | +The client interfaces |
| 11 | +--------------------- |
| 12 | + |
| 13 | +HTTPlug defines two HTTP client interfaces that we kept as simple as possible: |
| 14 | + |
| 15 | +* ``HttpClient`` defines a ``sendRequest`` method that sends a PSR-7 |
| 16 | + ``RequestInterface`` and either returns a PSR-7 ``ResponseInterface`` or |
| 17 | + throws an exception that implements ``Http\Client\Exception``. |
| 18 | + |
| 19 | +* ``HttpAsyncClient`` defines a ``sendAsyncRequest`` method that sends a request |
| 20 | + asynchronously and always returns a ``Http\Client\Promise``. |
6 | 21 |
|
7 | | -HTTPlug implementations typically are either HTTP clients of their own, or adapters wrapping existing clients |
8 | | -like Guzzle 6. In the latter case, they will depend on the required client implementation, |
9 | | -so you only need to require the adapter and not the actual client. |
| 22 | +Implementations |
| 23 | +--------------- |
10 | 24 |
|
| 25 | +PHP-HTTP offers two types of clients that implement the above interfaces: |
11 | 26 |
|
12 | | -There are two kind of implementations: |
| 27 | +1. Standalone clients that directly implement the interfaces. |
13 | 28 |
|
14 | | - - `php-http/client-implementation`_: |
15 | | - the synchronous implementation that waits for the response / error before returning from the ``sendRequest`` method. |
| 29 | + Examples: :doc:`/clients/curl-client` and :doc:`/clients/socket-client`. |
16 | 30 |
|
17 | | - - `php-http/async-client-implementation`_: |
18 | | - the asynchronous implementation that immediately returns a ``Http\Promise\Promise``, |
19 | | - allowing to send several requests in parallel and handling responses later. |
| 31 | +2. Adapters that wrap existing HTTP client, such as Guzzle. These adapters act |
| 32 | + as a bridge between the HTTPlug interfaces and the clients that do not (yet) |
| 33 | + implement these interfaces. |
20 | 34 |
|
21 | | -Check links above for the full list of implementations. |
| 35 | + Examples: :doc:`/clients/guzzle6-adapter` and :doc:`/clients/react-adapter`. |
22 | 36 |
|
23 | | -.. _`php-http/client-implementation`: https://packagist.org/providers/php-http/client-implementation |
24 | | -.. _`php-http/async-client-implementation`: https://packagist.org/providers/php-http/async-client-implementation: |
| 37 | +.. note:: |
| 38 | + |
| 39 | + Ideally, all HTTP client libraries out there will implement the HTTPlug |
| 40 | + interfaces. At that point, our adapters will no longer be necessary. |
25 | 41 |
|
26 | 42 | Usage in an application |
27 | 43 | ----------------------- |
28 | 44 |
|
29 | | -When writing an application, you need to require a concrete implementation_. |
| 45 | +When writing an application, you need to require a concrete implementation. |
30 | 46 |
|
31 | 47 | See :doc:`virtual-package` for more information on the topic of working with HTTPlug implementations. |
32 | 48 |
|
@@ -69,27 +85,20 @@ Best point them to the :doc:`virtual-package` page. |
69 | 85 | To be able to send requests, you should not depend on a specific PSR-7 implementation, |
70 | 86 | but use the :ref:`message-factory` system. |
71 | 87 |
|
72 | | -Framework Integration |
73 | | -^^^^^^^^^^^^^^^^^^^^^ |
74 | | - |
75 | | -HTTPlug can be used in any PHP based project. |
76 | | -Nonetheless, we provide particular integration for some popular frameworks: |
77 | | - |
78 | | -- HttplugBundle_: integration with the Symfony framework. |
79 | | - |
80 | 88 | History |
81 | 89 | ------- |
82 | 90 |
|
83 | | -This project has been started by `Eric Geloen`_ as `Ivory Http Adapter`_. It never made it to a stable release, |
84 | | -but it relied on PSR-7 which was not stable either that time. Because of the constantly changing PSR-7, |
85 | | -Eric had to rewrite the library over and over again (at least the message handling part, |
86 | | -which in most cases affected every adapter as well). |
| 91 | +This project has been started by `Eric Geloen`_ as `Ivory Http Adapter`_. It |
| 92 | +never made it to a stable release, but it relied on PSR-7 which was not stable |
| 93 | +either that time. Because of the constantly changing PSR-7, Eric had to rewrite |
| 94 | +the library over and over again (at least the message handling part, which in |
| 95 | +most cases affected every adapter as well). |
87 | 96 |
|
88 | | -In 2015, a decision has been made to move the library to its own organization, so PHP HTTP was born. |
| 97 | +In 2015, a decision has been made to move the library to its own organization, |
| 98 | +so PHP-HTTP was born. |
89 | 99 |
|
90 | | -See :doc:`migrating` for a guide how to migrate your code from the Ivory adapter to HTTPlug. |
| 100 | +See :doc:`migrating` for a guide how to migrate your code from the Ivory |
| 101 | +adapter. |
91 | 102 |
|
92 | | -.. _implementation: https://packagist.org/providers/php-http/client-implementation |
93 | | -.. _HttplugBundle: https://github.com/php-http/HttplugBundle |
94 | 103 | .. _`Eric Geloen`: https://github.com/egeloen |
95 | | -.. _`Ivory Http Adapter`: https://github.com/egeloen/ivory-http-adapter). |
| 104 | +.. _`Ivory Http Adapter`: https://github.com/egeloen/ivory-http-adapter |
0 commit comments