This guide explains how to set up a React application and make API requests using both React’s Fetch method and Axios. We’ll use the DummyAPI’s Movies endpoint as an example.
Step 1: Create a New React App
Using Vite
If you prefer Vite:
Using Bun
If you are using Bun:
Step 2: Install Axios (Optional)
To use Axios for API requests:
Or, if you’re using Bun:
Step 3: Setup Your React Component
Create a new component, e.g., src/components/MoviesComponent.jsx, and add the following code:
Step 4: Include Your Component
Add MoviesComponent to your App.jsx:
Step 5: Run Your App
Start your React application:
Step 6: View the Results
Open your browser and navigate to http://localhost:3000. You should see a list of movies fetched from the DummyAPI.
Conclusion
You’ve now set up a React application that can make API requests using both Fetch and Axios to the DummyAPI Movies endpoint. Explore further by integrating other endpoints and functionalities.