@@ -738,7 +738,7 @@ original HTTP client::
738
738
739
739
$client = new RetryableHttpClient(HttpClient::create());
740
740
741
- The `` RetryableHttpClient ` ` uses a
741
+ The :class: ` Symfony \\ Component \\ HttpClient \\ RetryableHttpClient ` uses a
742
742
:class: `Symfony\\ Component\\ HttpClient\\ Retry\\ RetryStrategyInterface ` to
743
743
decide if the request should be retried, and to define the waiting time between
744
744
each retry.
@@ -776,7 +776,8 @@ called when new data is uploaded or downloaded and at least once per second::
776
776
]);
777
777
778
778
Any exceptions thrown from the callback will be wrapped in an instance of
779
- ``TransportExceptionInterface `` and will abort the request.
779
+ :class: `Symfony\\ Contracts\\ HttpClient\\ Exception\\ TransportExceptionInterface `
780
+ and will abort the request.
780
781
781
782
HTTPS Certificates
782
783
~~~~~~~~~~~~~~~~~~
@@ -857,9 +858,10 @@ This component supports both the native PHP streams and cURL to make the HTTP
857
858
requests. Although both are interchangeable and provide the same features,
858
859
including concurrent requests, HTTP/2 is only supported when using cURL.
859
860
860
- ``HttpClient::create() `` selects the cURL transport if the `cURL PHP extension `_
861
- is enabled and falls back to PHP streams otherwise. If you prefer to select
862
- the transport explicitly, use the following classes to create the client::
861
+ The :method: `Symfony\\ Component\\ HttpClient\\ HttpClient::create ` method
862
+ selects the cURL transport if the `cURL PHP extension `_ is enabled and falls
863
+ back to PHP streams otherwise. If you prefer to select the transport
864
+ explicitly, use the following classes to create the client::
863
865
864
866
use Symfony\Component\HttpClient\CurlHttpClient;
865
867
use Symfony\Component\HttpClient\NativeHttpClient;
@@ -1040,8 +1042,9 @@ following methods::
1040
1042
Streaming Responses
1041
1043
~~~~~~~~~~~~~~~~~~~
1042
1044
1043
- Call the ``stream() `` method of the HTTP client to get *chunks * of the
1044
- response sequentially instead of waiting for the entire response::
1045
+ Call the :method: `Symfony\\ Contracts\\ HttpClient\\ HttpClientInterface::stream `
1046
+ method to get *chunks * of the response sequentially instead of waiting for the
1047
+ entire response::
1045
1048
1046
1049
$url = 'https://releases.ubuntu.com/18.04.1/ubuntu-18.04.1-desktop-amd64.iso';
1047
1050
$response = $client->request('GET', $url);
@@ -1071,8 +1074,7 @@ Canceling Responses
1071
1074
1072
1075
To abort a request (e.g. because it didn't complete in due time, or you want to
1073
1076
fetch only the first bytes of the response, etc.), you can either use the
1074
- ``cancel() `` method of
1075
- :class: `Symfony\\ Contracts\\ HttpClient\\ ResponseInterface `::
1077
+ :method: `Symfony\\ Contracts\\ HttpClient\\ ResponseInterface::cancel `::
1076
1078
1077
1079
$response->cancel();
1078
1080
@@ -1190,10 +1192,12 @@ If you look again at the snippet above, responses are read in requests' order.
1190
1192
But maybe the 2nd response came back before the 1st? Fully asynchronous operations
1191
1193
require being able to deal with the responses in whatever order they come back.
1192
1194
1193
- In order to do so, the ``stream() `` method of HTTP clients accepts a list of
1194
- responses to monitor. As mentioned :ref: `previously <http-client-streaming-responses >`,
1195
- this method yields response chunks as they arrive from the network. By replacing
1196
- the "foreach" in the snippet with this one, the code becomes fully async::
1195
+ In order to do so, the
1196
+ :method: `Symfony\\ Contracts\\ HttpClient\\ HttpClientInterface::stream `
1197
+ accepts a list of responses to monitor. As mentioned
1198
+ :ref: `previously <http-client-streaming-responses >`, this method yields response
1199
+ chunks as they arrive from the network. By replacing the "foreach" in the
1200
+ snippet with this one, the code becomes fully async::
1197
1201
1198
1202
foreach ($client->stream($responses) as $response => $chunk) {
1199
1203
if ($chunk->isFirst()) {
@@ -1330,7 +1334,8 @@ installed in your application::
1330
1334
// this won't hit the network if the resource is already in the cache
1331
1335
$response = $client->request('GET', 'https://example.com/cacheable-resource');
1332
1336
1333
- ``CachingHttpClient `` accepts a third argument to set the options of the ``HttpCache ``.
1337
+ :class: `Symfony\\ Component\\ HttpClient\\ CachingHttpClient` ` accepts a third argument
1338
+ to set the options of the :class: `Symfony\\ Component\\ HttpKernel\\ HttpCache\\ HttpCache `.
1334
1339
1335
1340
Consuming Server-Sent Events
1336
1341
----------------------------
@@ -1496,8 +1501,8 @@ it. As such, you should not use it in newly written code. The component is still
1496
1501
interoperable with libraries that require it thanks to the
1497
1502
:class: `Symfony\\ Component\\ HttpClient\\ HttplugClient ` class. Similarly to
1498
1503
:class: `Symfony\\ Component\\ HttpClient\\ Psr18Client ` implementing relevant parts of PSR-17,
1499
- `` HttplugClient `` also implements the factory methods defined in the related
1500
- ``php-http/message-factory `` package.
1504
+ :class: ` Symfony \\ Component \\ HttpClient \\ HttplugClient ` also implements the factory methods
1505
+ defined in the related ``php-http/message-factory `` package.
1501
1506
1502
1507
.. code-block :: terminal
1503
1508
@@ -1528,15 +1533,16 @@ that requires HTTPlug dependencies::
1528
1533
// [...]
1529
1534
}
1530
1535
1531
- Because ``HttplugClient `` implements the three interfaces, you can use it this way::
1536
+ Because :class: `Symfony\\ Component\\ HttpClient\\ HttplugClient ` implements the
1537
+ three interfaces,you can use it this way::
1532
1538
1533
1539
use Symfony\Component\HttpClient\HttplugClient;
1534
1540
1535
1541
$httpClient = new HttplugClient();
1536
1542
$apiClient = new SomeSdk($httpClient, $httpClient, $httpClient);
1537
1543
1538
- If you'd like to work with promises, `` HttplugClient `` also implements the
1539
- ``HttpAsyncClient `` interface. To use it, you need to install the
1544
+ If you'd like to work with promises, :class: ` Symfony \\ Component \\ HttpClient \\ HttplugClient `
1545
+ also implements the ``HttpAsyncClient `` interface. To use it, you need to install the
1540
1546
``guzzlehttp/promises `` package:
1541
1547
1542
1548
.. code-block :: terminal
@@ -1716,20 +1722,24 @@ external service. By not making actual HTTP requests there is no need to worry a
1716
1722
the service being online or the request changing state, for example deleting
1717
1723
a resource.
1718
1724
1719
- ``MockHttpClient `` implements the ``HttpClientInterface ``, just like any actual
1720
- HTTP client in this component. When you type-hint with ``HttpClientInterface ``
1721
- your code will accept the real client outside tests, while replacing it with
1722
- ``MockHttpClient `` in the test.
1725
+ :class: `Symfony\\ Component\\ HttpClient\\ MockHttpClient ` implements the
1726
+ :class: `Symfony\\ Contracts\\ HttpClient\\ HttpClientInterface `, just like any actual
1727
+ HTTP client in this component. When you type-hint with
1728
+ :class: `Symfony\\ Contracts\\ HttpClient\\ HttpClientInterface ` your code will accept
1729
+ the real client outside tests, while replacing it with
1730
+ :class: `Symfony\\ Component\\ HttpClient\\ MockHttpClient ` in the test.
1723
1731
1724
- When the ``request `` method is used on ``MockHttpClient ``, it will respond with
1725
- the supplied ``MockResponse ``. There are a few ways to use it, as described
1726
- below.
1732
+ When the ``request `` method is used on :class: `Symfony\\ Component\\ HttpClient\\ MockHttpClient `,
1733
+ it will respond with the supplied
1734
+ :class: `Symfony\\ Component\\ HttpClient\\ Response\\ MockResponse `. There are a few ways to use
1735
+ it, as described below.
1727
1736
1728
1737
HTTP Client and Responses
1729
1738
~~~~~~~~~~~~~~~~~~~~~~~~~
1730
1739
1731
- The first way of using ``MockHttpClient `` is to pass a list of responses to its
1732
- constructor. These will be yielded in order when requests are made::
1740
+ The first way of using :class: `Symfony\\ Component\\ HttpClient\\ MockHttpClient `
1741
+ is to pass a list of responses to its constructor. These will be yielded
1742
+ in order when requests are made::
1733
1743
1734
1744
use Symfony\Component\HttpClient\MockHttpClient;
1735
1745
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -1744,8 +1754,8 @@ constructor. These will be yielded in order when requests are made::
1744
1754
$response1 = $client->request('...'); // returns $responses[0]
1745
1755
$response2 = $client->request('...'); // returns $responses[1]
1746
1756
1747
- Another way of using `` MockHttpClient `` is to pass a callback that generates the
1748
- responses dynamically when it's called::
1757
+ Another way of using :class: ` Symfony \\ Component \\ HttpClient \\ MockHttpClient ` is to
1758
+ pass a callback that generates the responses dynamically when it's called::
1749
1759
1750
1760
use Symfony\Component\HttpClient\MockHttpClient;
1751
1761
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -1787,7 +1797,9 @@ assertions on the request before returning the mocked response::
1787
1797
.. tip ::
1788
1798
1789
1799
Instead of using the first argument, you can also set the (list of)
1790
- responses or callbacks using the ``setResponseFactory() `` method::
1800
+ responses or callbacks using the
1801
+ :method: `Symfony\\ Component\\ HttpClient\\ MockHttpClient::setResponseFactory `
1802
+ method::
1791
1803
1792
1804
$responses = [
1793
1805
new MockResponse($body1, $info1),
@@ -1799,7 +1811,8 @@ assertions on the request before returning the mocked response::
1799
1811
1800
1812
.. versionadded :: 5.4
1801
1813
1802
- The ``setResponseFactory() `` method was introduced in Symfony 5.4.
1814
+ The :method: `Symfony\\ Component\\ HttpClient\\ MockHttpClient::setResponseFactory `
1815
+ method was introduced in Symfony 5.4.
1803
1816
1804
1817
If you need to test responses with HTTP status codes different than 200,
1805
1818
define the ``http_code `` option::
@@ -1815,10 +1828,12 @@ define the ``http_code`` option::
1815
1828
$response = $client->request('...');
1816
1829
1817
1830
The responses provided to the mock client don't have to be instances of
1818
- ``MockResponse ``. Any class implementing ``ResponseInterface `` will work (e.g.
1819
- ``$this->createMock(ResponseInterface::class) ``).
1831
+ :class: `Symfony\\ Component\\ HttpClient\\ Response\\ MockResponse `. Any class
1832
+ implementing :class: `Symfony\\ Contracts\\ HttpClient\\ ResponseInterface `
1833
+ will work (e.g. ``$this->createMock(ResponseInterface::class) ``).
1820
1834
1821
- However, using ``MockResponse `` allows simulating chunked responses and timeouts::
1835
+ However, using :class: `Symfony\\ Component\\ HttpClient\\ Response\\ MockResponse `
1836
+ allows simulating chunked responses and timeouts::
1822
1837
1823
1838
$body = function () {
1824
1839
yield 'hello';
@@ -1910,7 +1925,8 @@ Then configure Symfony to use your callback:
1910
1925
Testing Request Data
1911
1926
~~~~~~~~~~~~~~~~~~~~
1912
1927
1913
- The ``MockResponse `` class comes with some helper methods to test the request:
1928
+ The :class: `Symfony\\ Component\\ HttpClient\\ Response\\ MockResponse ` class comes
1929
+ with some helper methods to test the request:
1914
1930
1915
1931
* ``getRequestMethod() `` - returns the HTTP method;
1916
1932
* ``getRequestUrl() `` - returns the URL the request would be sent to;
@@ -1919,8 +1935,9 @@ The ``MockResponse`` class comes with some helper methods to test the request:
1919
1935
1920
1936
.. versionadded :: 5.2
1921
1937
1922
- The ``getRequestMethod() `` and ``getRequestUrl() `` methods were introduced
1923
- in Symfony 5.2.
1938
+ The :method: `Symfony\\ Component\\ HttpClient\\ Response\\ MockResponse::getRequestMethod `
1939
+ and :method: `Symfony\\ Component\\ HttpClient\\ Response\\ MockResponse::getRequestUrl `
1940
+ methods were introduced in Symfony 5.2.
1924
1941
1925
1942
Usage example::
1926
1943
0 commit comments