JamesRobertSutcliffe / personality-music-recommender

A music recommender web app that bases reccomendations on personality type. Developed with next.js, Typescript, PostgreSQL and docker.
https://personality-music-recommender-jer1.vercel.app/
0 stars 0 forks source link

Set up mock data to avoid calling Spotify API #66

Open patdel0 opened 1 year ago

patdel0 commented 1 year ago

We are developing a project that heavily interacts with the Spotify API. However, during the development phase, frequent refreshes and numerous API calls are being made which result in hitting the rate limits imposed by Spotify. To circumvent this issue, an environment-specific configuration should be used to manage API requests based on the environment our application is running in.

The proposed solution is to create a wrapper for the fetch requests and handle it accordingly. Something along these lines:


function fetchAPIData(endpoint) {
  if (process.env.ENVIRONMENT === 'development') {
    return Promise.resolve(mockData);
  } 
  return fetch(`https://api.spotify.com/v1/${endpoint}`);
}