MellKam / soundify

🎧 Lightweight integration with the Spotify Web API for modern Javascript runtimes
https://npmjs.com/@soundify/web-api
MIT License
25 stars 3 forks source link

Functions or class methods for api calls? #17

Closed MellKam closed 1 year ago

MellKam commented 1 year ago

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:

MellKam commented 1 year ago

I decided to go with functions