This pull request introduces a reusable fetchDataFromTMDB function to handle API requests to the TMDB (The Movie Database) API. The function abstracts the logic for making fetch requests to the TMDB API by dynamically constructing the endpoint URL and including the required API key, which is stored in the .env.local file for security.
Changes:
Created the fetchDataFromTMDB function in utile/fetchDataFromTMDB.js.
The function takes a path parameter that specifies the API route and appends it to the TMDB base URL.
API key is loaded from environment variables using process.env.Public_API_KEY.
Error handling is implemented to catch any issues during the API request and log meaningful error messages.
Usage:
The fetchDataFromTMDB function can be reused throughout the project to fetch data from the TMDB API by passing a suitable endpoint. For example, it can be used in a component like this:
This pull request introduces a reusable
fetchDataFromTMDB
function to handle API requests to the TMDB (The Movie Database) API. The function abstracts the logic for making fetch requests to the TMDB API by dynamically constructing the endpoint URL and including the required API key, which is stored in the.env.local
file for security.Changes:
fetchDataFromTMDB
function inutile/fetchDataFromTMDB.js
.path
parameter that specifies the API route and appends it to the TMDB base URL.process.env.Public_API_KEY
.Usage: The
fetchDataFromTMDB
function can be reused throughout the project to fetch data from the TMDB API by passing a suitable endpoint. For example, it can be used in a component like this: