Skip to content

Commit 3b411f1

Browse files
[HttpClient] Add withOptions() to HttplugClient and Psr18Client
1 parent 7c64f45 commit 3b411f1

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
@@ -1435,6 +1435,27 @@ Now you can make HTTP requests with the PSR-18 client as follows:
14351435
14361436
$content = json_decode($response->getBody()->getContents(), true);
14371437
1438+
You can also pass a set of default options to your client thanks to the
1439+
``Psr18Client::withOptions()`` method::
1440+
1441+
use Symfony\Component\HttpClient\Psr18Client;
1442+
1443+
$client = (new Psr18Client())
1444+
->withOptions([
1445+
'base_uri' => 'https://symfony.com',
1446+
'headers' => [
1447+
'Accept' => 'application/json',
1448+
],
1449+
]);
1450+
1451+
$request = $client->createRequest('GET', '/versions.json');
1452+
1453+
// ...
1454+
1455+
.. versionadded:: 6.2
1456+
1457+
The ``Psr18Client::withOptions()`` method was introduced in Symfony 6.2.
1458+
14381459
HTTPlug
14391460
~~~~~~~
14401461

@@ -1523,6 +1544,24 @@ Then you're ready to go::
15231544
// wait for all remaining promises to resolve
15241545
$httpClient->wait();
15251546

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

0 commit comments

Comments
 (0)