Day 4 of 100daysofcode : RESTful API Integration
What I Built:
Today, I learned about RESTful APIs and implemented an endpoint in my e-commerce project to fetch a list of products from the backend. I also explored how the frontend interacts with the backend to display this data dynamically.
What I Learned:
- What are RESTful APIs?
REST stands for Representational State Transfer, which is a design pattern for creating scalable web services.
A RESTful API allows communication between a client (frontend) and a server (backend) using HTTP methods such as:
GET: Retrieve data.
POST: Send data to the server.
PUT/PATCH: Update existing data.
DELETE: Remove data.
- How RESTful APIs Work:
The backend exposes endpoints (URLs) that the frontend can call to perform specific actions.
For example:
- Backend endpoint: /api/products (fetch all products).
- Frontend calls this URL using an HTTP GET request and receives a list of products in JSON format.
- The client then uses this data to render it visually in the user interface.
Key Takeaways:
- RESTful APIs allow seamless communication between the frontend and backend.
- Learned how to fetch data using the fetch API in React and dynamically render it.
- MongoDB Compass is a helpful tool for adding and managing data during development.
Below is an example of how I fetch API from backend:
lebanon-mug 100daysofcode