5.x.x to 6.x.x
#
SpotifyAPI.Web#
InitializationIn 5.x
, a new SpotifyWebAPI
instance could be created without supplying necessary values, since they were implemented as properties. With 6.x
, necessary values have to be given in the constructor and SpotifyWebAPI
has been renamed to SpotifyClient
. Also, SpotifyClientConfig
has been introduced to give a better configuration experience, including retry handlers, automatic authenticators and proxy configurations.
For some performance guides, have a look at the Configuration Guide
#
ProxyIn 5.x
, the proxy configuration could be passed to the SpotifyWebAPI
constructor. In 6.x
, they're part of the HTTP Client. The built-in http client supports proxies out of the box:
#
Calling API EndpointsIn 5.x
, there was one big instance to support all API endpoints. Parameters to these endpoints were passed directly as method parameters. Optional parameters were nullable and could be excluded. In 6.x
, every endpoint group (albums
, tracks
, userprofile
) has their own API-Client, which is available as a property in a SpotifyClient
instance. While URI path parameters are still passed as method parameter, query and body parameters are now passed as a grouped class instance, where required parameters are needed in the constructor and optional parameters can be supplied as properties. All endpoints are also only implemented as async methods.
All required arguments are checked for non-null values. If it's null, the methods will throw a ArgumentNullException
#
Error/Header HandlingIn 5.x
, all response models included a base error model, with properties like Headers
, Error
and HasError
. This was not a good decision since response models should be clean and only contain API response data. In 6.x
, error handling is Exception
based. For example, if the access token is invalid, calling API endpoints will throw a APIUnauthorizedException
. If you hit the API too many times, the method will throw a APITooManyRequestsException
. They all derive from a base exception APIException
, which is also thrown in more general cases, e.g bad request input parameters. If you're interested in the headers of the last response, you can use spotify.LastResponse
, make sure there is only one thread using this instance!
More Info: Error Handling
#
SpotifyAPI.Web.AuthIn 5.x
, SpotifyAPI.Web.Auth
contained every logic related to the OAuth flows. In 6.x
, SpotifyAPI.Web.Auth
is only required if you need a HTTP Server for handling OAuth responses. For example, if you're in a ASP.NET environment or just use the Client Credentials flow, there is no need to install SpotifyAPI.Web.Auth
anymore.
#
Authorization Code AuthAs an example, this shows how to convert a 5.x
authorization code flow to 6.x
:
While it is more code to write, there is a better seperation of concerns. For example, it is able to construct a LoginRequest
without starting a server. This LoginRequest
can also be used to forward the user to in a web-based context. The same auth server EmbedIOAuthServer
can be used to receive AuthorizationCodes
and ImplictGrants
responses.