Currently, api calls are presented as separate functions, such as this one.
export const getCurrentUserProfile = (spotifyClient: ISpotifyClient) => {
return spotifyClient.fetch<UserPrivate>("/me");
};
// Usage example
const spotifyClient = new SpotifyClient(...);
const user = await getCurrentUserProfile(spotifyClient);
But in most api libraries, you can see a single class that contains all the api calls, so you can just do that.
const spotifyAPI = new SpotifyAPI()
const user = await spotifyAPI.getCurrentUserProfile();
What do you prefer to use?
Please write what you think about it. You can just "prefer functions" or "prefer class".
From my point of view, I can highlight some pros and cons:
Pros
Easy to treeshake in a web bundle.
Decomposition. Much easier to support a bunch of functions than one big class (in my opinion).
Cons.
A class is just easier to use. You can pass it throughout your application and use it. It's awkwardly to pass a client every time just to use call. Idk
Currently, api calls are presented as separate functions, such as this one.
But in most api libraries, you can see a single class that contains all the api calls, so you can just do that.
What do you prefer to use? Please write what you think about it. You can just "prefer functions" or "prefer class".
From my point of view, I can highlight some pros and cons: