Skip to content

Commit a4c08b8

Browse files
committed
minor #17756 [HttpClient] Add withOptions() to HttplugClient and Psr18Client (alexandre-daubois)
This PR was merged into the 6.2 branch. Discussion ---------- [HttpClient] Add withOptions() to HttplugClient and Psr18Client Resolves #17382 Commits ------- 3b411f1 [HttpClient] Add withOptions() to HttplugClient and Psr18Client
2 parents 846b12b + 3b411f1 commit a4c08b8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

http_client.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,27 @@ Now you can make HTTP requests with the PSR-18 client as follows:
14391439
14401440
$content = json_decode($response->getBody()->getContents(), true);
14411441
1442+
You can also pass a set of default options to your client thanks to the
1443+
``Psr18Client::withOptions()`` method::
1444+
1445+
use Symfony\Component\HttpClient\Psr18Client;
1446+
1447+
$client = (new Psr18Client())
1448+
->withOptions([
1449+
'base_uri' => 'https://symfony.com',
1450+
'headers' => [
1451+
'Accept' => 'application/json',
1452+
],
1453+
]);
1454+
1455+
$request = $client->createRequest('GET', '/versions.json');
1456+
1457+
// ...
1458+
1459+
.. versionadded:: 6.2
1460+
1461+
The ``Psr18Client::withOptions()`` method was introduced in Symfony 6.2.
1462+
14421463
HTTPlug
14431464
~~~~~~~
14441465

@@ -1527,6 +1548,24 @@ Then you're ready to go::
15271548
// wait for all remaining promises to resolve
15281549
$httpClient->wait();
15291550

1551+
You can also pass a set of default options to your client thanks to the
1552+
``HttplugClient::withOptions()`` method::
1553+
1554+
use Psr\Http\Message\ResponseInterface;
1555+
use Symfony\Component\HttpClient\HttplugClient;
1556+
1557+
$httpClient = (new HttplugClient())
1558+
->withOptions([
1559+
'base_uri' => 'https://my.api.com',
1560+
]);
1561+
$request = $httpClient->createRequest('GET', '/');
1562+
1563+
// ...
1564+
1565+
.. versionadded:: 6.2
1566+
1567+
The ``HttplugClient::withOptions()`` method was introduced in Symfony 6.2.
1568+
15301569
Native PHP Streams
15311570
~~~~~~~~~~~~~~~~~~
15321571

0 commit comments

Comments
 (0)