Skip to content

Commit

Permalink
[10.x] Add withQueryParameters to the HTTP client (#47297)
Browse files Browse the repository at this point in the history
* Add `withQueryParameters` to the HTTP client

Some APIs require some query parameters to be always set. For example auth token (even though this isn't a great practice).

With this new helper, we can create a macro with the query parameter always set.

* Add more tests for `withQueryParameters` with arrays

See laravel/framework#47297 (comment)

* formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
mnapoli and taylorotwell authored Jun 22, 2023
1 parent d8e91f0 commit cf8b286
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,21 @@ public function bodyFormat(string $format)
});
}

/**
* Set the given query parameters in the request URI.
*
* @param array $parameters
* @return $this
*/
public function withQueryParameters(array $parameters)
{
return tap($this, function () use ($parameters) {
$this->options = array_merge_recursive($this->options, [
'query' => $parameters,
]);
});
}

/**
* Specify the request's content type.
*
Expand Down

0 comments on commit cf8b286

Please sign in to comment.