A Library for the Spotify web API

I just finished creating a library for the Spotify web API!


It uses combine to make chaining asynchronous requests a breeze and is designed to integrate well with SwiftUI. I would really appreciate some feedback.
1 Like

Cool. I just took a brief look at the code and it seems nicely written and documented. Have you thought about sorting your URL query parameters to improve caching?

Also, is there a reason it only supports Darwin platforms?

Thank you for taking the time to look over my code, Karl. The reason it only supports Apple platforms is because it uses Apple's Combine framework, which, as far as I can tell, is only supported on Apple platforms. It may be possible for me to reimplement the library using another framework like RxSwift so that it can be used for linux platforms.

I'm also very intrigued by your suggestion that sorting URL query parameters improves caching. How do you know this? And who's doing the caching? Spotify?

It’s a well-known good practice. Here’s the CloudFlare page about it: https://support.cloudflare.com/hc/en-us/articles/206776797-Understanding-Query-String-Sort . Most network caches work the same way - they have to be conservative and assume that differently-ordered query strings are processed differently by the server, even though almost no servers do that (if the keys are unique). Those caches could be at the OS level, or at Spotify, or somewhere in between.

That’s a shame. If anybody was to recommend that Swift developers stay away from Combine, or to hope that it dies a quick and painful death (just like, hypothetically...), I guess they’d point to examples like this where cool software is made unavailable on certain platforms for no real reason.

In the mean time, you might try OpenCombine to support non-Apple platforms. AFAIK the API is compatible with Combine so it shouldn’t require you to make large code changes - mostly just conditionally importing the correct framework.

Terms of Service

Privacy Policy

Cookie Policy