Why We Use APIs in React


🧱 Setup Checklist


⚙️ 1. Using the Fetch API


🧩 Example: Fetching Posts (using useEffect + useState)


💡 Notes:


⚙️ 2. Using Axios


⚖️ Fetch vs Axios — Quick Comparison

Feature Fetch Axios
Default Built‑in JS API External library
JSON parsing Manual (res.json()) Automatic
Error handling Must check response manually Automatically throws
Interceptors ❌ Not available ✅ Available
Simplicity Lightweight Versatile features

🧩 Example: POST Request with Axios