Options
All
  • Public
  • Public/Protected
  • All
Menu

@thomasngrlt/spotify-web-api-ts

spotify-web-api-ts

An isomorphic TypeScript wrapper for Spotify's Web API
View the docs ยป

npm minzipped size license

Main Workflow codecov semantic-release

Fork of adamgrieger/spotify-web-api-ts

Additions

  • feat(spotifyaxios.ts): wait and retry after rate limiting
  • feat(spotifyaxios.ts): cache GET requests response data
  • feat(spotifyaxios.ts): add spotify error message to axios error: Issue in the initial repo

Installation

yarn

yarn add @thomasngrlt/spotify-web-api-ts

npm

npm install @thomasngrlt/spotify-web-api-ts

Basic Example

import { SpotifyWebApi } from 'spotify-web-api-ts';

const spotify = new SpotifyWebApi({ accessToken: '<YOUR_ACCESS_TOKEN_HERE>' });

const { artists } = await spotify.albums.getAlbum('1uzfGk9vxMXfaZ2avqwxod');

console.log(artists.map(artist => artist.name));
// Array [ "Against All Logic" ]

Example using Redis Cache

import { SpotifyWebApi } from 'spotify-web-api-ts';
import { createClient } from 'redis';

const client = createClient();
await client.connect();

const spotify = new SpotifyWebApi({
accessToken: '<YOUR_ACCESS_TOKEN_HERE>',
getCache: (key: string) =>
client.get(key).then(data => (data ? JSON.parse(data) : null)),
setCache: (key: string, expiration, value) =>
redisClient.set(key, JSON.stringify(value), { EX: expiration }).then(),
});

const album1 = await spotify.albums.getAlbum('1uzfGk9vxMXfaZ2avqwxod');
// cache-control header is "public, max-age=73485"

const album2 = await spotify.albums.getAlbum('1uzfGk9vxMXfaZ2avqwxod');
// No additional api calls was made

Generated using TypeDoc