Skip to content

Commit 394fc95

Browse files
[HttpClient] Replace a few classes and methods occurrences by their source code link
1 parent 3e76637 commit 394fc95

File tree

1 file changed

+61
-41
lines changed

1 file changed

+61
-41
lines changed

http_client.rst

Lines changed: 61 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ method to retrieve a new instance of the client with new default options::
148148

149149
.. versionadded:: 5.3
150150

151-
The ``withOptions()`` method was introduced in Symfony 5.3.
151+
The :method:`Symfony\\Contracts\\HttpClient\\HttpClientInterface::withOptions`
152+
method was introduced in Symfony 5.3.
152153

153154
Some options are described in this guide:
154155

@@ -481,8 +482,10 @@ each request (which overrides any global authentication):
481482
.. note::
482483

483484
The NTLM authentication mechanism requires using the cURL transport.
484-
By using ``HttpClient::createForBaseUri()``, we ensure that the auth credentials
485-
won't be sent to any other hosts than https://example.com/.
485+
By using the ``createForBaseUri()`` method of
486+
:class:`Symfony\\Component\\HttpClient\\HttpClient`, we ensure that
487+
the auth credentials won't be sent to any other hosts than
488+
https://example.com/.
486489

487490
Query String Parameters
488491
~~~~~~~~~~~~~~~~~~~~~~~
@@ -739,7 +742,7 @@ original HTTP client::
739742

740743
$client = new RetryableHttpClient(HttpClient::create());
741744

742-
The ``RetryableHttpClient`` uses a
745+
The :class:`Symfony\\Component\\HttpClient\\RetryableHttpClient` uses a
743746
:class:`Symfony\\Component\\HttpClient\\Retry\\RetryStrategyInterface` to
744747
decide if the request should be retried, and to define the waiting time between
745748
each retry.
@@ -777,7 +780,8 @@ called when new data is uploaded or downloaded and at least once per second::
777780
]);
778781

779782
Any exceptions thrown from the callback will be wrapped in an instance of
780-
``TransportExceptionInterface`` and will abort the request.
783+
:class:`Symfony\\Contracts\\HttpClient\\Exception\\TransportExceptionInterface`
784+
and will abort the request.
781785

782786
HTTPS Certificates
783787
~~~~~~~~~~~~~~~~~~
@@ -858,9 +862,10 @@ This component supports both the native PHP streams and cURL to make the HTTP
858862
requests. Although both are interchangeable and provide the same features,
859863
including concurrent requests, HTTP/2 is only supported when using cURL.
860864

861-
``HttpClient::create()`` selects the cURL transport if the `cURL PHP extension`_
862-
is enabled and falls back to PHP streams otherwise. If you prefer to select
863-
the transport explicitly, use the following classes to create the client::
865+
The ``create()`` method of :class:`Symfony\\Component\\HttpClient\\HttpClient`
866+
selects the cURL transport if the `cURL PHP extension`_ is enabled and falls
867+
back to PHP streams otherwise. If you prefer to select the transport
868+
explicitly, use the following classes to create the client::
864869

865870
use Symfony\Component\HttpClient\CurlHttpClient;
866871
use Symfony\Component\HttpClient\NativeHttpClient;
@@ -1041,8 +1046,9 @@ following methods::
10411046
Streaming Responses
10421047
~~~~~~~~~~~~~~~~~~~
10431048

1044-
Call the ``stream()`` method of the HTTP client to get *chunks* of the
1045-
response sequentially instead of waiting for the entire response::
1049+
Call the ``stream()`` method of :class:`Symfony\\Contracts\\HttpClient\\HttpClientInterface`
1050+
to get *chunks* of the response sequentially instead of waiting for the
1051+
entire response::
10461052

10471053
$url = 'https://releases.ubuntu.com/18.04.1/ubuntu-18.04.1-desktop-amd64.iso';
10481054
$response = $client->request('GET', $url);
@@ -1072,8 +1078,7 @@ Canceling Responses
10721078

10731079
To abort a request (e.g. because it didn't complete in due time, or you want to
10741080
fetch only the first bytes of the response, etc.), you can either use the
1075-
``cancel()`` method of
1076-
:class:`Symfony\\Contracts\\HttpClient\\ResponseInterface`::
1081+
``cancel()`` method of :class:`Symfony\\Contracts\\HttpClient\\ResponseInterface`::
10771082

10781083
$response->cancel();
10791084

@@ -1191,10 +1196,12 @@ If you look again at the snippet above, responses are read in requests' order.
11911196
But maybe the 2nd response came back before the 1st? Fully asynchronous operations
11921197
require being able to deal with the responses in whatever order they come back.
11931198

1194-
In order to do so, the ``stream()`` method of HTTP clients accepts a list of
1195-
responses to monitor. As mentioned :ref:`previously <http-client-streaming-responses>`,
1196-
this method yields response chunks as they arrive from the network. By replacing
1197-
the "foreach" in the snippet with this one, the code becomes fully async::
1199+
In order to do so, the ``stream()`` method of
1200+
:class:`Symfony\\Contracts\\HttpClient\\HttpClientInterface` accepts a list of
1201+
responses to monitor. As mentioned
1202+
:ref:`previously <http-client-streaming-responses>`, this method yields response
1203+
chunks as they arrive from the network. By replacing the "foreach" in the
1204+
snippet with this one, the code becomes fully async::
11981205

11991206
foreach ($client->stream($responses) as $response => $chunk) {
12001207
if ($chunk->isFirst()) {
@@ -1331,7 +1338,8 @@ installed in your application::
13311338
// this won't hit the network if the resource is already in the cache
13321339
$response = $client->request('GET', 'https://example.com/cacheable-resource');
13331340

1334-
``CachingHttpClient`` accepts a third argument to set the options of the ``HttpCache``.
1341+
:class:`Symfony\\Component\\HttpClient\\CachingHttpClient`` accepts a third argument
1342+
to set the options of the :class:`Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache`.
13351343

13361344
Consuming Server-Sent Events
13371345
----------------------------
@@ -1497,8 +1505,8 @@ it. As such, you should not use it in newly written code. The component is still
14971505
interoperable with libraries that require it thanks to the
14981506
:class:`Symfony\\Component\\HttpClient\\HttplugClient` class. Similarly to
14991507
:class:`Symfony\\Component\\HttpClient\\Psr18Client` implementing relevant parts of PSR-17,
1500-
``HttplugClient`` also implements the factory methods defined in the related
1501-
``php-http/message-factory`` package.
1508+
:class:`Symfony\\Component\\HttpClient\\HttplugClient` also implements the factory methods
1509+
defined in the related ``php-http/message-factory`` package.
15021510

15031511
.. code-block:: terminal
15041512
@@ -1529,15 +1537,16 @@ that requires HTTPlug dependencies::
15291537
// [...]
15301538
}
15311539

1532-
Because ``HttplugClient`` implements the three interfaces, you can use it this way::
1540+
Because :class:`Symfony\\Component\\HttpClient\\HttplugClient` implements the
1541+
three interfaces,you can use it this way::
15331542

15341543
use Symfony\Component\HttpClient\HttplugClient;
15351544

15361545
$httpClient = new HttplugClient();
15371546
$apiClient = new SomeSdk($httpClient, $httpClient, $httpClient);
15381547

1539-
If you'd like to work with promises, ``HttplugClient`` also implements the
1540-
``HttpAsyncClient`` interface. To use it, you need to install the
1548+
If you'd like to work with promises, :class:`Symfony\\Component\\HttpClient\\HttplugClient`
1549+
also implements the ``HttpAsyncClient`` interface. To use it, you need to install the
15411550
``guzzlehttp/promises`` package:
15421551

15431552
.. code-block:: terminal
@@ -1717,20 +1726,24 @@ external service. By not making actual HTTP requests there is no need to worry a
17171726
the service being online or the request changing state, for example deleting
17181727
a resource.
17191728

1720-
``MockHttpClient`` implements the ``HttpClientInterface``, just like any actual
1721-
HTTP client in this component. When you type-hint with ``HttpClientInterface``
1722-
your code will accept the real client outside tests, while replacing it with
1723-
``MockHttpClient`` in the test.
1729+
:class:`Symfony\\Component\\HttpClient\\MockHttpClient` implements the
1730+
:class:`Symfony\\Contracts\\HttpClient\\HttpClientInterface`, just like any actual
1731+
HTTP client in this component. When you type-hint with
1732+
:class:`Symfony\\Contracts\\HttpClient\\HttpClientInterface` your code will accept
1733+
the real client outside tests, while replacing it with
1734+
:class:`Symfony\\Component\\HttpClient\\MockHttpClient` in the test.
17241735

1725-
When the ``request`` method is used on ``MockHttpClient``, it will respond with
1726-
the supplied ``MockResponse``. There are a few ways to use it, as described
1727-
below.
1736+
When the ``request`` method is used on :class:`Symfony\\Component\\HttpClient\\MockHttpClient`,
1737+
it will respond with the supplied
1738+
:class:`Symfony\\Component\\HttpClient\\Response\\MockResponse`. There are a few ways to use
1739+
it, as described below.
17281740

17291741
HTTP Client and Responses
17301742
~~~~~~~~~~~~~~~~~~~~~~~~~
17311743

1732-
The first way of using ``MockHttpClient`` is to pass a list of responses to its
1733-
constructor. These will be yielded in order when requests are made::
1744+
The first way of using :class:`Symfony\\Component\\HttpClient\\MockHttpClient`
1745+
is to pass a list of responses to its constructor. These will be yielded
1746+
in order when requests are made::
17341747

17351748
use Symfony\Component\HttpClient\MockHttpClient;
17361749
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -1745,8 +1758,8 @@ constructor. These will be yielded in order when requests are made::
17451758
$response1 = $client->request('...'); // returns $responses[0]
17461759
$response2 = $client->request('...'); // returns $responses[1]
17471760

1748-
Another way of using ``MockHttpClient`` is to pass a callback that generates the
1749-
responses dynamically when it's called::
1761+
Another way of using :class:`Symfony\\Component\\HttpClient\\MockHttpClient` is to
1762+
pass a callback that generates the responses dynamically when it's called::
17501763

17511764
use Symfony\Component\HttpClient\MockHttpClient;
17521765
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -1761,7 +1774,9 @@ responses dynamically when it's called::
17611774
.. tip::
17621775

17631776
Instead of using the first argument, you can also set the (list of)
1764-
responses or callbacks using the ``setResponseFactory()`` method::
1777+
responses or callbacks using the
1778+
:method:`Symfony\\Component\\HttpClient\\MockHttpClient::setResponseFactory`
1779+
method::
17651780

17661781
$responses = [
17671782
new MockResponse($body1, $info1),
@@ -1773,7 +1788,8 @@ responses dynamically when it's called::
17731788

17741789
.. versionadded:: 5.4
17751790

1776-
The ``setResponseFactory()`` method was introduced in Symfony 5.4.
1791+
The :method:`Symfony\\Component\\HttpClient\\MockHttpClient::setResponseFactory`
1792+
method was introduced in Symfony 5.4.
17771793

17781794
If you need to test responses with HTTP status codes different than 200,
17791795
define the ``http_code`` option::
@@ -1789,10 +1805,12 @@ define the ``http_code`` option::
17891805
$response = $client->request('...');
17901806

17911807
The responses provided to the mock client don't have to be instances of
1792-
``MockResponse``. Any class implementing ``ResponseInterface`` will work (e.g.
1793-
``$this->createMock(ResponseInterface::class)``).
1808+
:class:`Symfony\\Component\\HttpClient\\Response\\MockResponse`. Any class
1809+
implementing :class:`Symfony\\Contracts\\HttpClient\\ResponseInterface`
1810+
will work (e.g. ``$this->createMock(ResponseInterface::class)``).
17941811

1795-
However, using ``MockResponse`` allows simulating chunked responses and timeouts::
1812+
However, using :class:`Symfony\\Component\\HttpClient\\Response\\MockResponse`
1813+
allows simulating chunked responses and timeouts::
17961814

17971815
$body = function () {
17981816
yield 'hello';
@@ -1884,7 +1902,8 @@ Then configure Symfony to use your callback:
18841902
Testing Request Data
18851903
~~~~~~~~~~~~~~~~~~~~
18861904

1887-
The ``MockResponse`` class comes with some helper methods to test the request:
1905+
The :class:`Symfony\\Component\\HttpClient\\Response\\MockResponse` class comes
1906+
with some helper methods to test the request:
18881907

18891908
* ``getRequestMethod()`` - returns the HTTP method;
18901909
* ``getRequestUrl()`` - returns the URL the request would be sent to;
@@ -1893,8 +1912,9 @@ The ``MockResponse`` class comes with some helper methods to test the request:
18931912

18941913
.. versionadded:: 5.2
18951914

1896-
The ``getRequestMethod()`` and ``getRequestUrl()`` methods were introduced
1897-
in Symfony 5.2.
1915+
The :method:`Symfony\\Component\\HttpClient\\Response\\MockResponse::getRequestMethod`
1916+
and :method:`Symfony\\Component\\HttpClient\\Response\\MockResponse::getRequestUrl`
1917+
methods were introduced in Symfony 5.2.
18981918

18991919
Usage example::
19001920

0 commit comments

Comments
 (0)