Skip to content
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

New feature: provide your own HTTP client? #276

Open
adnweedon opened this issue Jun 5, 2024 · 2 comments
Open

New feature: provide your own HTTP client? #276

adnweedon opened this issue Jun 5, 2024 · 2 comments

Comments

@adnweedon
Copy link

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!

@jwilsson
Copy link
Owner

jwilsson commented 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!

@jwilsson
Copy link
Owner

jwilsson commented 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 😅

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

No branches or pull requests

2 participants