What is light-spotify?
light-spotify is a Spotify wrapper to make it easy to work with Spotify's API.
Installation
For npm:
npm i light-spotify
For yarn:
yarn add light-spotify
Usage
Its important to make sure that you have a valid access token to make requests. To make an access token, you can use the simple code below.
const baseUrl = "https://accounts.spotify.com/api/token";
const getData = await fetch(baseUrl, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization:
"Basic " +
new Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString("base64"),
},
body: "grant_type=client_credentials",
})
.then(res => res.json())
.then(data => {
console.log(data)
.
})
Then, create a new instance of the package.
import { LightSpotify } from 'light-spotify';
const SpotifyAPI = new LightSpotify();
SpotifyAPI.setAccessToken = 'ACCESS_TOKEN';
console.log(Spotify.getAccessToken);
Requests
Making requests with light-spotify is easy. Want to get multiple albums? Easy.
const { LightSpotify } = require("light-spotify");
const spotify = new LightSpotify();
const albumIds = ['ID1', 'ID2', 'ID3'];
spotify.setAccessToken = 'asd';
spotify
.getMultipleAlbums(spotify.getAccessToken, albumIds, 'US')
.then((i) => {
console.log(i.data);
})
.catch(console.error);
Oh yeah. And we also have full Typescript support. :)
Check out /docs/TOC.md for all data requests that you can make.
Contributions
Any contributions are welcome. Check out CONTRIBUTING.md for more info.