A tiny API to retrieve statistics from Spotify for a specific account. Designed to be deployed using Cloudflare Workers, and built using Miniflare to enable things like local development and testing.
Before starting up the repo, you will need to obtain authentication from Spotify to use your account. I have created a script to handle the difficult part of this process, which you can use by running:
npm run spotify:auth
This will give you a Refresh Token, which will then be used repeatedly to keep the worker authenticated to use Spotify data.
You will then need to save some secret values with Wrangler, so that the Web Worker can access them. You will need to run the following to save these values:
wrangler secret put SPOTIFY_CLIENT_ID
# Paste your Spotify Client ID when prompted
wrangler secret put SPOTIFY_CLIENT_SECRET
# Paste your Spotify Client Secret when prompted
wrangler secret put SPOTIFY_REFRESH_TOKEN
# Paste your Refresh Token when prompted
Once this is complete, you should be able to make successful calls to the Web Worker's endpoint.
- Clone the repo, and install dependencies using
npm install
- Run
npm run dev
to start the local development server (with live reload!) - You should now be able to make calls to the endpoints exposed (listed below), and get data back.
# Start remote development server using wrangler
$ npm run dev:remote
# Run tests - these have not been implemented yet but will be!
$ npm test
# Run type checking
$ npm run types:check
# Deploy using wrangler
$ npm run deploy
/top
Retrieves a list of top tracks for the Spotify account