@@ -43,8 +43,18 @@ low-level HTTP client that makes requests, like the following ``GET`` request::
43
43
$content = $response->toArray();
44
44
// $content = ['id' => 521583, 'name' => 'symfony-docs', ...]
45
45
46
+ Performance
47
+ -----------
48
+
49
+ The component is built for maximum HTTP performance. By design, it is compatible
50
+ with HTTP/2 and with doing concurrent asynchronous streamed and multiplexed
51
+ requests/responses. Even when doing regular synchronous calls, this design
52
+ allows keeping connections to remote hosts open between requests, improving
53
+ performance by saving repetitive DNS resolution, SSL negotiation, etc.
54
+ To leverage all these design benefits, the cURL extension is needed.
55
+
46
56
Enabling cURL Support
47
- ---------------------
57
+ ~~~~~~~~~~~~~~~~~~~~~
48
58
49
59
This component supports both the native PHP streams and cURL to make the HTTP
50
60
requests. Although both are interchangeable and provide the same features,
@@ -68,7 +78,7 @@ not configurable and cURL will be used automatically if the cURL PHP extension
68
78
is installed and enabled. Otherwise, the native PHP streams will be used.
69
79
70
80
HTTP/2 Support
71
- --------------
81
+ ~~~~~~~~~~~~~~
72
82
73
83
When requesting an ``https `` URL, HTTP/2 is enabled by default if libcurl >= 7.36
74
84
is used. To force HTTP/2 for ``http `` URLs, you need to enable it explicitly via
@@ -609,14 +619,55 @@ regular expression applied to relative URLs::
609
619
'https://api\.github\.com/'
610
620
);
611
621
612
- PSR-18 Compatibility
613
- --------------------
622
+ Interoperability
623
+ ----------------
624
+
625
+ The component is interoperable with two different abstractions for HTTP clients:
626
+ `Symfony Contracts `_ and `PSR-18 `_. If your application uses libraries that need
627
+ any of them, the component is compatible with both. They also benefit from
628
+ :ref: `autowiring aliases <service-autowiring-alias >` when the
629
+ :ref: `framework bundle <framework-bundle-configuration >` is used.
630
+
631
+ If you are writing or maintaining a library that makes HTTP requests, you can
632
+ decouple it from any specific HTTP client implementations by coding against
633
+ either Symfony Contracts (recommended) or PSR-18.
634
+
635
+ Symfony Contracts
636
+ ~~~~~~~~~~~~~~~~~
637
+
638
+ The interfaces found in the ``symfony/http-client-contracts `` package define
639
+ the primary abstractions implemented by the component. Its entry point is the
640
+ :class: `Symfony\\ Contracts\\ HttpClient\\ HttpClientInterface `. That's the
641
+ interface you need to code against when a client is needed::
642
+
643
+ use Symfony\Contracts\HttpClient\HttpClientInterface;
644
+
645
+ class MyApiLayer
646
+ {
647
+ private $client;
648
+
649
+ public function __construct(HttpClientInterface $client)
650
+ {
651
+ $this->client = $client
652
+ }
653
+
654
+ // [...]
655
+ }
656
+
657
+ All request options mentioned above (e.g. timeout management) are also defined
658
+ in the wordings of the interface, so that any compliant implementations (like
659
+ this component) is guaranteed to provide them. That's a major difference with
660
+ the PSR-18 abstraction, which provides none related to the transport itself.
661
+
662
+ Another major feature covered by the Symfony Contracts is async/multiplexing,
663
+ as described in the previous sections.
664
+
665
+ PSR-18
666
+ ~~~~~~
614
667
615
- This component uses and implements abstractions defined by the
616
- ``symfony/http-client-contracts ``. It also implements the `PSR-18 `_ (HTTP Client)
617
- specifications via the :class: `Symfony\\ Component\\ HttpClient\\ Psr18Client `
618
- class, which is an adapter to turn a Symfony ``HttpClientInterface `` into a
619
- PSR-18 ``ClientInterface ``.
668
+ This component implements the `PSR-18 `_ (HTTP Client) specifications via the
669
+ :class: `Symfony\\ Component\\ HttpClient\\ Psr18Client ` class, which is an adapter
670
+ to turn a Symfony ``HttpClientInterface `` into a PSR-18 ``ClientInterface ``.
620
671
621
672
To use it, you need the ``psr/http-client `` package and a `PSR-17 `_ implementation:
622
673
@@ -765,3 +816,4 @@ However, using ``MockResponse`` allows simulating chunked responses and timeouts
765
816
.. _`cURL PHP extension` : https://php.net/curl
766
817
.. _`PSR-17` : https://www.php-fig.org/psr/psr-17/
767
818
.. _`PSR-18` : https://www.php-fig.org/psr/psr-18/
819
+ .. _`Symfony Contracts` : https://github.com/symfony/contracts
0 commit comments