File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -1435,6 +1435,27 @@ Now you can make HTTP requests with the PSR-18 client as follows:
1435
1435
1436
1436
$content = json_decode($response->getBody()->getContents(), true);
1437
1437
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
+
1438
1459
HTTPlug
1439
1460
~~~~~~~
1440
1461
@@ -1523,6 +1544,24 @@ Then you're ready to go::
1523
1544
// wait for all remaining promises to resolve
1524
1545
$httpClient->wait();
1525
1546
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
+
1526
1565
Native PHP Streams
1527
1566
~~~~~~~~~~~~~~~~~~
1528
1567
You can’t perform that action at this time.
0 commit comments