Skip to content

[HttpClient] Add withOptions() to HttplugClient and Psr18Client #17756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions http_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~

Expand Down Expand Up @@ -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
~~~~~~~~~~~~~~~~~~

Expand Down
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