From 3b411f118ad0ab9ec709c7645b5fbb0bdb178bbc Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 16 Jan 2023 18:52:49 +0100 Subject: [PATCH] [HttpClient] Add withOptions() to HttplugClient and Psr18Client --- http_client.rst | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/http_client.rst b/http_client.rst index f7715ce2a1d..7cffb09399c 100644 --- a/http_client.rst +++ b/http_client.rst @@ -1435,6 +1435,27 @@ Now you can make HTTP requests with the PSR-18 client as follows: $content = json_decode($response->getBody()->getContents(), true); +You can also pass a set of default options to your client thanks to the +``Psr18Client::withOptions()`` method:: + + use Symfony\Component\HttpClient\Psr18Client; + + $client = (new Psr18Client()) + ->withOptions([ + 'base_uri' => 'https://symfony.com', + 'headers' => [ + 'Accept' => 'application/json', + ], + ]); + + $request = $client->createRequest('GET', '/versions.json'); + + // ... + +.. versionadded:: 6.2 + + The ``Psr18Client::withOptions()`` method was introduced in Symfony 6.2. + HTTPlug ~~~~~~~ @@ -1523,6 +1544,24 @@ Then you're ready to go:: // wait for all remaining promises to resolve $httpClient->wait(); +You can also pass a set of default options to your client thanks to the +``HttplugClient::withOptions()`` method:: + + use Psr\Http\Message\ResponseInterface; + use Symfony\Component\HttpClient\HttplugClient; + + $httpClient = (new HttplugClient()) + ->withOptions([ + 'base_uri' => 'https://my.api.com', + ]); + $request = $httpClient->createRequest('GET', '/'); + + // ... + +.. versionadded:: 6.2 + + The ``HttplugClient::withOptions()`` method was introduced in Symfony 6.2. + Native PHP Streams ~~~~~~~~~~~~~~~~~~ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy