Skip to content

Commit 7e36278

Browse files
committed
mention psr-18
1 parent 5072ccc commit 7e36278

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

clients.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ Composer Virtual Packages
4848

4949
Virtual packages are a way to specify the dependency on an implementation of an interface-only repository
5050
without forcing a specific implementation. For HTTPlug, the virtual packages are called `php-http/client-implementation`_
51-
and `php-http/async-client-implementation`_.
51+
(though you should be using `psr/http-client-implementation`_ to use PSR-18) and `php-http/async-client-implementation`_.
5252

5353
There is no library registered with those names. However, all client implementations (including client adapters) for
5454
HTTPlug use the ``provide`` section to tell composer that they do provide the client-implementation.
5555

5656
.. _`php-http/client-implementation`: https://packagist.org/providers/php-http/client-implementation
57+
.. _`psr/http-client-implementation`: https://packagist.org/providers/psr/http-client-implementation
5758
.. _`php-http/async-client-implementation`: https://packagist.org/providers/php-http/async-client-implementation
5859
.. _`Adapter pattern`: https://en.wikipedia.org/wiki/Adapter_pattern
5960
.. _`Liskov substitution principle`: https://en.wikipedia.org/wiki/Liskov_substitution_principle

httplug/introduction.rst

+19-9
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ Client Interfaces
1212

1313
HTTPlug defines two HTTP client interfaces that we kept as simple as possible:
1414

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``.
15+
* PSR-18 defines the ``ClientInterface`` with a ``sendRequest`` method that
16+
accepts a PSR-7 ``RequestInterface`` and either returns a PSR-7
17+
``ResponseInterface`` or throws an exception that implements
18+
``Psr\Http\Client\ClientExceptionInterface``.
1819

19-
* ``HttpAsyncClient`` defines a ``sendAsyncRequest`` method that sends a request
20-
asynchronously and always returns a ``Http\Client\Promise``.
20+
HTTPlug has the compatible interface ``HttpClient`` which now extends the
21+
PSR-18 interface to allow migrating to PSR-18.
22+
23+
* ``HttpAsyncClient`` defines a ``sendAsyncRequest`` method that sends a PSR-7
24+
request asynchronously and always returns a ``Http\Client\Promise``.
2125
See :doc:`../components/promise` for more information.
2226

2327
Implementations
@@ -29,16 +33,22 @@ PHP-HTTP offers two types of clients that implement the above interfaces:
2933

3034
Examples: :doc:`/clients/curl-client` and :doc:`/clients/socket-client`.
3135

32-
2. Adapters that wrap existing HTTP client, such as Guzzle. These adapters act
36+
2. Adapters that wrap existing HTTP clients, such as Guzzle. These adapters act
3337
as a bridge between the HTTPlug interfaces and the clients that do not (yet)
3438
implement these interfaces.
3539

36-
Examples: :doc:`/clients/guzzle6-adapter` and :doc:`/clients/react-adapter`.
40+
More and more clients implement PSR-18 directly. If that is all you need, we
41+
recommend not using HTTPlug as it would only add overhead. However, as there
42+
is no PSR for asynchronous requests yet, you can use the adapters to do such
43+
requests without binding yourself to a specific implementation.
44+
45+
Examples: :doc:`/clients/guzzle7-adapter` and :doc:`/clients/react-adapter`.
3746

3847
.. note::
3948

40-
Ideally, all HTTP client libraries out there will implement the HTTPlug
41-
interfaces. At that point, our adapters will no longer be necessary.
49+
Ideally, there will be a PSR for asynchronous requests and all HTTP client
50+
libraries out there will implement PSR-18 and the not yet existing PSR. At
51+
that point, our adapters will no longer be necessary.
4252

4353
Usage
4454
-----

httplug/library-developers.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Manage Dependencies
1111
-------------------
1212

1313
To depend on *some* HTTP client, specify either
14-
``php-http/client-implementation`` or ``php-http/async-client-implementation``
14+
``psr/http-client-implementation`` for PSR-18 synchronous requests or
15+
``php-http/async-client-implementation`` for asynchronous requests
1516
in your library’s ``composer.json``. These are virtual Composer packages that
1617
will throw an error if no concrete client was found:
1718

@@ -20,7 +21,7 @@ will throw an error if no concrete client was found:
2021
{
2122
"name": "you/and-your-awesome-library",
2223
"require": {
23-
"php-http/client-implementation": "^1.0"
24+
"psr/http-client-implementation": "^1.0"
2425
}
2526
}
2627
@@ -50,7 +51,7 @@ in the ``require-dev`` section in your library’s ``composer.json``. You could
5051
{
5152
"name": "you/and-your-awesome-library",
5253
"require": {
53-
"php-http/client-implementation": "^1.0"
54+
"psr/http-client-implementation": "^1.0"
5455
},
5556
"require-dev": {
5657
"php-http/mock-client": "^1.0"
@@ -96,7 +97,7 @@ Putting it all together your final ``composer.json`` is much likely to look simi
9697
"name": "you/and-your-awesome-library",
9798
"require": {
9899
"psr/http-message": "^1.0",
99-
"php-http/client-implementation": "^1.0",
100+
"psr/http-client-implementation": "^1.0",
100101
"php-http/httplug": "^1.0",
101102
"php-http/message-factory": "^1.0",
102103
"php-http/discovery": "^1.0"

index.rst

+10-6
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ PHP-HTTP: standardized HTTP for PHP
77
:alt: HTTPlug Logo
88

99
PHP-HTTP is the next step in standardizing HTTP interaction for PHP packages.
10+
1011
It builds on top of PSR-7_, which defines interfaces for HTTP requests and
11-
responses. PSR-7 does not describe, however, the way you should create requests
12-
or send them. PHP-HTTP aims to fill that gap by offering an HTTP client
13-
interface: HTTPlug.
12+
responses. The HTTPlug HTTP client interface has been standardized in PSR-18_
13+
to define synchronous HTTP requests. When using a client that implements PSR-18,
14+
we recommend directly using PSR-18 and not HTTPlug nor our adapters.
15+
16+
However, PSR-18 does not define asynchronous requests. HTTPlug provides interfaces
17+
for those, but to do that also needs to define how :doc:`promises <components/promise>`
18+
are implemented.
1419

1520
PHP-HTTP has three goals:
1621

@@ -19,9 +24,8 @@ PHP-HTTP has three goals:
1924

2025
2. Provide good quality HTTP-related packages to the PHP community.
2126

22-
3. Over time, make HTTPlug a PHP Standards Recommendation (PSR) so that clients
23-
will directly implement the HTTPlug interface and our adapters are no longer
24-
needed.
27+
3. Now that PSR-18 exists, we miss a PSR for asynchronous requests. This is blocked
28+
by not having a PSR for promises.
2529

2630
HTTPlug
2731
-------

0 commit comments

Comments
 (0)