API integration is a core part of modern web applications. Whether you’re building with React or Angular, learning how to fetch and handle data from APIs will level up your frontend development skills.
Here are practical tasks that will help you master API integration step-by-step in both frameworks.
πΉ Task: Read API documentation and understand endpoints, methods (GET, POST, PUT, DELETE), and responses.
π Example:
Check a public API like https://jsonplaceholder.typicode.com
π Skill Gained: Grasp the structure of APIs before implementing.
πΉ Task: Fetch data from a public API and display it in your app.
π React Example:
useEffect(() => {
fetch('https://jsonplaceholder.typicode.com/posts')
.then(res => res.json())
.then(data => setPosts(data));
}, []);
π Angular Example:
this.http.get('https://jsonplaceholder.typicode.com/posts')
.subscribe(data => this.posts = data);
π Skill Gained: Learn basic data fetching and display.
πΉ Task: Add a loader while data is being fetched.
π Skill Gained: Handle asynchronous operations and improve UX.
πΉ Task: Use try/catch
in React or .catch()
in Angular to display error messages if the API fails.
π React Example:
try {
const res = await fetch(url);
if (!res.ok) throw new Error("Failed to fetch data");
} catch (err) {
console.error(err);
}
π Skill Gained: Error handling and user feedback.
πΉ Task: Build a form and send its data to the API using POST.
π Angular Example:
this.http.post('https://api.example.com/users', this.userForm.value)
.subscribe(response => console.log(response));
π Skill Gained: Learn how to send data from frontend to backend.
πΉ Task: Use axios
in React and HttpClient
in Angular for cleaner requests.
π React Axios Example:
axios.get('https://api.example.com/data')
.then(res => console.log(res.data));
π Skill Gained: Use of powerful HTTP libraries for better handling.
πΉ Task: Render fetched data using loops (.map()
in React and *ngFor
in Angular).
π React:
posts.map(post => <li key={post.id}>{post.title}</li>)
π Angular:
<li *ngFor="let post of posts">{{ post.title }}</li>
π Skill Gained: Dynamic rendering and component logic.
πΉ Task: Fetch specific data using dynamic IDs in the route (e.g., /users/5
).
π Skill Gained: Routing + API logic together.
πΉ Task: Filter data or search by query using an input field and trigger API calls.
π Skill Gained: Debouncing, controlled inputs, and efficient API use.
πΉ Task: Use tokens (JWT) in headers to call protected APIs.
π React Axios Example:
axios.get('/secure-data', {
headers: { Authorization: `Bearer ${token}` }
});
π Skill Gained: Secure APIs and authentication flow.
API integration is the bridge between frontend and backend. By mastering these practical tasks in both React and Angular, you build the ability to create powerful, data-driven applications. Practice each step in small projects—like blogs, user dashboards, or product listings—to cement your understanding.
The key is consistency, clear understanding of asynchronous flows, and learning how to communicate with real-time data sources.