React.js Technical Test for TA'AL
- Node.js
- Git
-
Clone the repository:
git clone https://github.com/Mohammad-Obidat/unsplashAPI.git
-
Navigate to the project directory
cd unsplashAPI -
Install the dependencies
either on root (backend), or cd client (frontend)
npm install
-
Create a
.envfile in the root directory of the project. -
Add the following environment variables to the
.envfile:
UNSPLASH_ACCESS_KEY=<your-Unsplash-API-key>
PORT=<your-app-port>To start the MERN app, follow these steps:
- Start the Node.js server:
node server- Start the React development server (in a new terminal tab):
npm start- Open your web browser and visit
http://localhost:<your-app-port>to see the app in action.
Describe the structure of your project directory, including key files and directories.
This project utilizes the Unsplash API to fetch and display high-quality images. Follow the instructions below to obtain the necessary credentials and configure the API integration.
To use the Unsplash API, you'll need to create an account and obtain an API access key. Here's how:
- Visit the Unsplash Developer website.
- Sign in or create a new account.
- Create a new application to generate an API access key.
- Note down the access key for future use.
Once you have obtained the API access key, follow these steps to configure the project:
- In the project directory, locate the
.envfile. - Open the
.envfile in a text editor. - Set the
UNSPLASH_ACCESS_KEYenvironment variable with your API access key:
UNSPLASH_ACCESS_KEY=
To fetch images from the Unsplash API, you can utilize the provided functions and endpoints. Here's an example of how to use the API integration:
// Example code for fetching images using the Unsplash API
// Import the necessary libraries or modules
// ...
// Set up the API request
const accessKey = process.env.UNSPLASH_ACCESS_KEY;
const endpoint = `https://api.unsplash.com/photos/random?client_id=${accessKey}`;
// Make the API request to fetch a random image
fetch(endpoint)
.then((response) => response.json())
.then((data) => {
// Handle the API response and use the image data
// ...
})
.catch((error) => {
// Handle any errors that occurred during the API request
// ...
});For more details on using the Unsplash API, visit the Unsplash Documentation website.
This project is licensed under the MIT License.