Skip to content

[12.x] HTTP Client: add mergeUrlParameters() to combine URL parameters without overwriting#57282

Merged
taylorotwell merged 2 commits into
laravel:12.xfrom
leek:patch-1
Oct 6, 2025
Merged

[12.x] HTTP Client: add mergeUrlParameters() to combine URL parameters without overwriting#57282
taylorotwell merged 2 commits into
laravel:12.xfrom
leek:patch-1

Conversation

@leek

@leek leek commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

This PR introduces mergeUrlParameters(array $parameters = []) to Illuminate\Http\Client\PendingRequest.

Today, withUrlParameters() replaces the entire parameter map, which makes it hard to define global parameters (e.g., in a macro) and then add/override endpoint-specific parameters later. The new method merges into the existing map, letting later calls override only the keys they provide.

Backwards compatibility
  • Fully BC: existing withUrlParameters() behavior is unchanged.
  • No impact on public signatures other than the additive new method.
Usage example
Http::macro('service', function () {
    return Http::baseUrl('https://api.example.com')
        ->withUrlParameters(['version' => 'v1', 'tenant' => 'acme']);
});

$response = Http::service()
    ->mergeUrlParameters(['tenant' => 'beta'])
    ->get('/{version}/tenants/{tenant}/users');

Add method to merge URL parameters into existing map.
@leek leek changed the title HTTP Client: add mergeUrlParameters() to combine URL parameters without overwriting [12.x] HTTP Client: add mergeUrlParameters() to combine URL parameters without overwriting Oct 6, 2025
@taylorotwell taylorotwell merged commit 920724c into laravel:12.x Oct 6, 2025
64 checks passed
@taylorotwell

Copy link
Copy Markdown
Member

I kinda think they should just always merge.

@leek leek deleted the patch-1 branch October 6, 2025 23:16
@guenbakku

Copy link
Copy Markdown

It looks like that the MR title doesn't quite match the final code. There is no new method mergeUrlParameters; instead, the behavior of withUrlParameters was updated to merge (instead of replace).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants