[GH-ISSUE #276] New feature: provide your own HTTP client? #204

Closed
opened 2026-02-27 19:26:35 +03:00 by kerem · 2 comments
Owner

Originally created by @adnweedon on GitHub (Jun 5, 2024).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/276

I was just wondering whether you might be open to a change from using curl directly, to allowing an HTTP client to be optionally provided to the package? The primary use-case for us is that we have an instrumented Guzzle/PSR-18 client, which if the package could use it, would give us helpful performance/tracing/debugging information!

Originally created by @adnweedon on GitHub (Jun 5, 2024). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/276 I was just wondering whether you might be open to a change from using curl directly, to allowing an HTTP client to be optionally provided to the package? The primary use-case for us is that we have an instrumented Guzzle/PSR-18 client, which if the package could use it, would give us helpful performance/tracing/debugging information!
kerem closed this issue 2026-02-27 19:26:35 +03:00
Author
Owner

@jwilsson commented on GitHub (Jun 6, 2024):

Hey!
It is possible (albeit poorly documented) to pass your own Request instance to the library, e.g.

class MyRequest extends SpotifyWebAPI\Request
{
    public function send()
    {
      // Do your thing
    }
}

$request = new MyRequest();

$session = new SpotifyWebAPI\Session('CLIENT_ID', 'CLIENT_SECRET', 'REDIRECT_URI', $request);
$api = new SpotifyWebAPI\SpotifyWebAPI([], null, $request);

Let me just improve the docs a bit and add an additional helper or two and you'll be good to go!

<!-- gh-comment-id:2152077621 --> @jwilsson commented on GitHub (Jun 6, 2024): Hey! It is possible (albeit poorly documented) to pass your own `Request` instance to the library, e.g. ```php class MyRequest extends SpotifyWebAPI\Request { public function send() { // Do your thing } } $request = new MyRequest(); $session = new SpotifyWebAPI\Session('CLIENT_ID', 'CLIENT_SECRET', 'REDIRECT_URI', $request); $api = new SpotifyWebAPI\SpotifyWebAPI([], null, $request); ``` Let me just improve the docs a bit and add an additional helper or two and you'll be good to go!
Author
Owner

@jwilsson commented on GitHub (Jun 6, 2024):

Added some additional docs with some helper methods that could some in useful, Passing a Custom Request Instance. Hope this helps!

And just to provide some additional background. Given the age of this project, adding "proper" PSR-18 etc. support feels like a bit much and not worth the effort and possible breakage. With that said however, I have been chipping away at a "V2" with much more modern PHP features, full support for PSR-18 and friends, plus better typings but it's a slow process 😅

<!-- gh-comment-id:2152174165 --> @jwilsson commented on GitHub (Jun 6, 2024): Added some additional docs with some helper methods that could some in useful, [Passing a Custom Request Instance](https://github.com/jwilsson/spotify-web-api-php/blob/482508df74e2b851be44d3c6ac7cbacae500ce7a/docs/examples/passing-a-custom-request-instance.md). Hope this helps! And just to provide some additional background. Given the age of this project, adding "proper" PSR-18 etc. support feels like a bit much and not worth the effort and possible breakage. With that said however, I have been chipping away at a "V2" with much more modern PHP features, full support for PSR-18 and friends, plus better typings but it's a slow process 😅
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-web-api-php#204
No description provided.