mirror of
https://github.com/ramsayleung/rspotify.git
synced 2026-04-26 07:55:55 +03:00
[PR #186] [MERGED] Separate HTTP client from the Spotify client #296
Labels
No labels
Stale
bug
discussion
enhancement
good first issue
good first issue
help wanted
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/rspotify#296
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ramsayleung/rspotify/pull/186
Author: @marioortizmanero
Created: 2/16/2021
Status: ✅ Merged
Merged: 2/20/2021
Merged by: @ramsayleung
Base:
master← Head:separate-http📝 Commits (8)
5c9a000Some initial work8195f8ddocumentation824e3d3fix docd5f4c93finish reqwest20d47d1compiling correctly now284398dureq working5e3fa6einline endpoint_getddc9a19Merge branch 'master' into separate-http📊 Changes
5 files changed (+260 additions, -139 deletions)
View changed files
📝
src/client.rs(+84 -81)📝
src/http/mod.rs(+129 -11)📝
src/http/reqwest.rs(+28 -25)📝
src/http/ureq.rs(+18 -21)📝
src/oauth2.rs(+1 -1)📄 Description
So I've come to the conclusion that the HTTP client should be separate from the Spotify client, and be kept as one of its members instead. This completely separates the logic from the HTTP abstraction with the Spotify client and makes the code more modular and cleaner.
This means that, to implement the
get,post, and similar methods inside the http-specific modules (likehttp:reqwest,http::ureq), instead of doingimpl Spotifydirectly, the implementation is forReqwestClientorUreqClient. The latter is then exported asHTTPClientso that it can be used to perform requests. All these clients must implement the same trait as before,BaseClient, which is now renamed asBaseHTTPClient. This is just to make sure the interface exported byureqandreqwestis the same.What's now improved:
No need for this part in the Spotify client, which was hardcoded to be used later on only on the
httpmodule, a quite bad practice:This is now a generic HTTP struct, which is always included, be it reqwest or ureq. For the latter it will be empty because it doesn't really require an instance of its client, but it avoids the conditional compilation of this field:
Before, the reqwest and ureq implementations of the HTTP features were tied to what we needed to perform HTTP requests:
Now, the HTTP client doesn't know about the authentication process required for Spotify requests, and this has to be implemented in the Spotify client instead. Thus, this part is no longer repeated for each HTTP implementation (ureq, reqwest).
What's worse:
This requires implementing wrappers over the HTTP clients. We currently need two different wrappers:
get,post, and similars, which only append the Spotify url to the relative one. These are used for the authentication process, to request the token and similars.These wrappers aren't really necessary, but they guarantee we aren't forgetting to append the spotify url or the auth headers, while also reducing the endpoint boilerplate required (a goal in #127).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.