Soundify is a lightweight and flexible library for seamless communication with Spotify API, designed to work smoothly with TypeScript, Deno, Node.js, and client-side JavaScript. It's open source and provides an easy-to-use interface for accessing Spotify's data.
- Multiplatform: You can use it with Node.js, Deno on the server, or with client-side JavaScript.
- Modern: It leverages modern web APIs like native
fetch
,crypto
,URLSearchParams
and doesn't require any external dependencies. - Lightweight and treeshakable: It's designed to be as small as possible (exact size TBD).
- TypeScript first: It's built with TypeScript and provides great support for it out of the box.
- Comprehensive Spotify Auth support: It can handle all Spotify Auth flows and automatically refreshes access tokens.
- Great docs: The library comes with extensive documentation and lots of examples to help you get started.
npm i soundify-web-api
Unfortunately, the soundify
package on the NPM was already taken ;(
// For nodejs (server-side)
import { ... } from "soundify-web-api"
// For client-side javascript
import { ... } from "soundify-web-api/web"
Deno deno.land/x/soundify
// Import from denoland (recomended)
import { ... } from "https://deno.land/x/soundify/mod.ts"
// Import from github repo main branch
import { ... } from "https://raw.githubusercontent.com/MellKam/soundify/main/mod.ts";
First of all, you should already have a Spotify app created. If not, go and create one here https://developer.spotify.com/dashboard
Let's write "Hello world!" with soundify.
import { SpotifyClient, getCurrentUserProfile } from "soundify-web-api";
const client = new SpotifyClient(
authProvider: "YOUR_ACCESS_TOKEN",
)
const user = await getCurrentUserProfile(client);
console.log(user);
There are 4 authorization flows, and this package supports all of them It may be difficult for beginners to choose one. In this case, you can read Spotify's official documentation on the subject. How to chose authorization flow?
Flow | Access user resources | Requires secret key (SERVER-SIDE) | Access token refresh |
---|---|---|---|
Authorization code | Yes | Yes | Yes |
Authorization code with PKCE | Yes | No | Yes |
Client credentials | No | Yes | No |
Implicit grant | Yes | No | No |
As from spotify docs: "Implicit grant is not recommended because it returns a token in a URL instead of a trusted channel"
Thatnk's ChatGPT for helping to create this readme ❤️