@@ -724,7 +724,7 @@ original HTTP client::
724
724
725
725
$client = new RetryableHttpClient(HttpClient::create());
726
726
727
- The `` RetryableHttpClient ` ` uses a
727
+ The :class: ` Symfony \\ Component \\ HttpClient \\ RetryableHttpClient ` uses a
728
728
:class: `Symfony\\ Component\\ HttpClient\\ Retry\\ RetryStrategyInterface ` to
729
729
decide if the request should be retried, and to define the waiting time between
730
730
each retry.
@@ -762,7 +762,8 @@ called when new data is uploaded or downloaded and at least once per second::
762
762
]);
763
763
764
764
Any exceptions thrown from the callback will be wrapped in an instance of
765
- ``TransportExceptionInterface `` and will abort the request.
765
+ :class: `Symfony\\ Contracts\\ HttpClient\\ Exception\\ TransportExceptionInterface `
766
+ and will abort the request.
766
767
767
768
HTTPS Certificates
768
769
~~~~~~~~~~~~~~~~~~
@@ -835,9 +836,10 @@ This component supports both the native PHP streams and cURL to make the HTTP
835
836
requests. Although both are interchangeable and provide the same features,
836
837
including concurrent requests, HTTP/2 is only supported when using cURL.
837
838
838
- ``HttpClient::create() `` selects the cURL transport if the `cURL PHP extension `_
839
- is enabled and falls back to PHP streams otherwise. If you prefer to select
840
- the transport explicitly, use the following classes to create the client::
839
+ The :method: `Symfony\\ Component\\ HttpClient\\ HttpClient::create ` method
840
+ selects the cURL transport if the `cURL PHP extension `_ is enabled and falls
841
+ back to PHP streams otherwise. If you prefer to select the transport
842
+ explicitly, use the following classes to create the client::
841
843
842
844
use Symfony\Component\HttpClient\CurlHttpClient;
843
845
use Symfony\Component\HttpClient\NativeHttpClient;
@@ -1008,8 +1010,9 @@ following methods::
1008
1010
Streaming Responses
1009
1011
~~~~~~~~~~~~~~~~~~~
1010
1012
1011
- Call the ``stream() `` method of the HTTP client to get *chunks * of the
1012
- response sequentially instead of waiting for the entire response::
1013
+ Call the :method: `Symfony\\ Contracts\\ HttpClient\\ HttpClientInterface::stream `
1014
+ method to get *chunks * of the response sequentially instead of waiting for the
1015
+ entire response::
1013
1016
1014
1017
$url = 'https://releases.ubuntu.com/18.04.1/ubuntu-18.04.1-desktop-amd64.iso';
1015
1018
$response = $client->request('GET', $url);
@@ -1039,8 +1042,7 @@ Canceling Responses
1039
1042
1040
1043
To abort a request (e.g. because it didn't complete in due time, or you want to
1041
1044
fetch only the first bytes of the response, etc.), you can either use the
1042
- ``cancel() `` method of
1043
- :class: `Symfony\\ Contracts\\ HttpClient\\ ResponseInterface `::
1045
+ :method: `Symfony\\ Contracts\\ HttpClient\\ ResponseInterface::cancel `::
1044
1046
1045
1047
$response->cancel();
1046
1048
@@ -1158,10 +1160,12 @@ If you look again at the snippet above, responses are read in requests' order.
1158
1160
But maybe the 2nd response came back before the 1st? Fully asynchronous operations
1159
1161
require being able to deal with the responses in whatever order they come back.
1160
1162
1161
- In order to do so, the ``stream() `` method of HTTP clients accepts a list of
1162
- responses to monitor. As mentioned :ref: `previously <http-client-streaming-responses >`,
1163
- this method yields response chunks as they arrive from the network. By replacing
1164
- the "foreach" in the snippet with this one, the code becomes fully async::
1163
+ In order to do so, the
1164
+ :method: `Symfony\\ Contracts\\ HttpClient\\ HttpClientInterface::stream `
1165
+ accepts a list of responses to monitor. As mentioned
1166
+ :ref: `previously <http-client-streaming-responses >`, this method yields response
1167
+ chunks as they arrive from the network. By replacing the "foreach" in the
1168
+ snippet with this one, the code becomes fully async::
1165
1169
1166
1170
foreach ($client->stream($responses) as $response => $chunk) {
1167
1171
if ($chunk->isFirst()) {
@@ -1300,7 +1304,8 @@ installed in your application::
1300
1304
// this won't hit the network if the resource is already in the cache
1301
1305
$response = $client->request('GET', 'https://example.com/cacheable-resource');
1302
1306
1303
- ``CachingHttpClient `` accepts a third argument to set the options of the ``HttpCache ``.
1307
+ :class: `Symfony\\ Component\\ HttpClient\\ CachingHttpClient` ` accepts a third argument
1308
+ to set the options of the :class: `Symfony\\ Component\\ HttpKernel\\ HttpCache\\ HttpCache `.
1304
1309
1305
1310
Consuming Server-Sent Events
1306
1311
----------------------------
@@ -1479,8 +1484,8 @@ it. As such, you should not use it in newly written code. The component is still
1479
1484
interoperable with libraries that require it thanks to the
1480
1485
:class: `Symfony\\ Component\\ HttpClient\\ HttplugClient ` class. Similarly to
1481
1486
:class: `Symfony\\ Component\\ HttpClient\\ Psr18Client ` implementing relevant parts of PSR-17,
1482
- `` HttplugClient `` also implements the factory methods defined in the related
1483
- ``php-http/message-factory `` package.
1487
+ :class: ` Symfony \\ Component \\ HttpClient \\ HttplugClient ` also implements the factory methods
1488
+ defined in the related ``php-http/message-factory `` package.
1484
1489
1485
1490
.. code-block :: terminal
1486
1491
@@ -1511,15 +1516,16 @@ that requires HTTPlug dependencies::
1511
1516
// [...]
1512
1517
}
1513
1518
1514
- Because ``HttplugClient `` implements the three interfaces, you can use it this way::
1519
+ Because :class: `Symfony\\ Component\\ HttpClient\\ HttplugClient ` implements the
1520
+ three interfaces,you can use it this way::
1515
1521
1516
1522
use Symfony\Component\HttpClient\HttplugClient;
1517
1523
1518
1524
$httpClient = new HttplugClient();
1519
1525
$apiClient = new SomeSdk($httpClient, $httpClient, $httpClient);
1520
1526
1521
- If you'd like to work with promises, `` HttplugClient `` also implements the
1522
- ``HttpAsyncClient `` interface. To use it, you need to install the
1527
+ If you'd like to work with promises, :class: ` Symfony \\ Component \\ HttpClient \\ HttplugClient `
1528
+ also implements the ``HttpAsyncClient `` interface. To use it, you need to install the
1523
1529
``guzzlehttp/promises `` package:
1524
1530
1525
1531
.. code-block :: terminal
@@ -1712,20 +1718,24 @@ external service. By not making actual HTTP requests there is no need to worry a
1712
1718
the service being online or the request changing state, for example deleting
1713
1719
a resource.
1714
1720
1715
- ``MockHttpClient `` implements the ``HttpClientInterface ``, just like any actual
1716
- HTTP client in this component. When you type-hint with ``HttpClientInterface ``
1717
- your code will accept the real client outside tests, while replacing it with
1718
- ``MockHttpClient `` in the test.
1721
+ :class: `Symfony\\ Component\\ HttpClient\\ MockHttpClient ` implements the
1722
+ :class: `Symfony\\ Contracts\\ HttpClient\\ HttpClientInterface `, just like any actual
1723
+ HTTP client in this component. When you type-hint with
1724
+ :class: `Symfony\\ Contracts\\ HttpClient\\ HttpClientInterface ` your code will accept
1725
+ the real client outside tests, while replacing it with
1726
+ :class: `Symfony\\ Component\\ HttpClient\\ MockHttpClient ` in the test.
1719
1727
1720
- When the ``request `` method is used on ``MockHttpClient ``, it will respond with
1721
- the supplied ``MockResponse ``. There are a few ways to use it, as described
1722
- below.
1728
+ When the ``request `` method is used on :class: `Symfony\\ Component\\ HttpClient\\ MockHttpClient `,
1729
+ it will respond with the supplied
1730
+ :class: `Symfony\\ Component\\ HttpClient\\ Response\\ MockResponse `. There are a few ways to use
1731
+ it, as described below.
1723
1732
1724
1733
HTTP Client and Responses
1725
1734
~~~~~~~~~~~~~~~~~~~~~~~~~
1726
1735
1727
- The first way of using ``MockHttpClient `` is to pass a list of responses to its
1728
- constructor. These will be yielded in order when requests are made::
1736
+ The first way of using :class: `Symfony\\ Component\\ HttpClient\\ MockHttpClient `
1737
+ is to pass a list of responses to its constructor. These will be yielded
1738
+ in order when requests are made::
1729
1739
1730
1740
use Symfony\Component\HttpClient\MockHttpClient;
1731
1741
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -1740,8 +1750,8 @@ constructor. These will be yielded in order when requests are made::
1740
1750
$response1 = $client->request('...'); // returns $responses[0]
1741
1751
$response2 = $client->request('...'); // returns $responses[1]
1742
1752
1743
- Another way of using `` MockHttpClient `` is to pass a callback that generates the
1744
- responses dynamically when it's called::
1753
+ Another way of using :class: ` Symfony \\ Component \\ HttpClient \\ MockHttpClient ` is to
1754
+ pass a callback that generates the responses dynamically when it's called::
1745
1755
1746
1756
use Symfony\Component\HttpClient\MockHttpClient;
1747
1757
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -1778,7 +1788,9 @@ assertions on the request before returning the mocked response::
1778
1788
.. tip ::
1779
1789
1780
1790
Instead of using the first argument, you can also set the (list of)
1781
- responses or callbacks using the ``setResponseFactory() `` method::
1791
+ responses or callbacks using the
1792
+ :method: `Symfony\\ Component\\ HttpClient\\ MockHttpClient::setResponseFactory `
1793
+ method::
1782
1794
1783
1795
$responses = [
1784
1796
new MockResponse($body1, $info1),
@@ -1802,10 +1814,12 @@ define the ``http_code`` option::
1802
1814
$response = $client->request('...');
1803
1815
1804
1816
The responses provided to the mock client don't have to be instances of
1805
- ``MockResponse ``. Any class implementing ``ResponseInterface `` will work (e.g.
1806
- ``$this->createMock(ResponseInterface::class) ``).
1817
+ :class: `Symfony\\ Component\\ HttpClient\\ Response\\ MockResponse `. Any class
1818
+ implementing :class: `Symfony\\ Contracts\\ HttpClient\\ ResponseInterface `
1819
+ will work (e.g. ``$this->createMock(ResponseInterface::class) ``).
1807
1820
1808
- However, using ``MockResponse `` allows simulating chunked responses and timeouts::
1821
+ However, using :class: `Symfony\\ Component\\ HttpClient\\ Response\\ MockResponse `
1822
+ allows simulating chunked responses and timeouts::
1809
1823
1810
1824
$body = function () {
1811
1825
yield 'hello';
@@ -1893,7 +1907,8 @@ Then configure Symfony to use your callback:
1893
1907
Testing Request Data
1894
1908
~~~~~~~~~~~~~~~~~~~~
1895
1909
1896
- The ``MockResponse `` class comes with some helper methods to test the request:
1910
+ The :class: `Symfony\\ Component\\ HttpClient\\ Response\\ MockResponse ` class comes
1911
+ with some helper methods to test the request:
1897
1912
1898
1913
* ``getRequestMethod() `` - returns the HTTP method;
1899
1914
* ``getRequestUrl() `` - returns the URL the request would be sent to;
0 commit comments