frontend-api-integration-patterns
Helps your agent integrate the frontend with APIs. It uses patterns to handle errors, cancellations, and updates efficiently.
What it does
This tool helps connect your website or app to other online services more reliably. It teaches how to handle common issues that occur when information is being sent and received, ensuring everything works smoothly and without errors for the user.
When to use it
- ✓When connecting your website to a data service.
- ✓When you want to prevent old information from appearing on the screen.
- ✓To fix errors that happen when loading or sending data.
Example of what to ask your AI
“How do I prevent my website from showing old data when I'm fetching new information?”
Want more? Open the sections below.
How to use
The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.
Skill link
Ready-to-paste message
How it works
It organizes the code that communicates with other services, prevents duplicate requests from being sent, and ensures that if a connection fails, it can intelligently retry.
Installation
Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.
In the terminal (Claude Code, Codex, Cursor), in your project folder:
npx skills add sickn33/agentic-awesome-skills --skill frontend-api-integration-patternsOr download just the file:
curl -L https://raw.githubusercontent.com/sickn33/agentic-awesome-skills/main/plugins/agentic-awesome-skills-claude/skills/frontend-api-integration-patterns/SKILL.md -o SKILL.mdTechnical content (original SKILL.md)
Original text by the author, straight from GitHub.
Frontend API Integration Patterns
Overview
This skill provides production-ready patterns for integrating frontend applications with backend APIs.
Most frontend issues are not caused by APIs being difficult to call, but by incorrect handling of asynchronous behavior—leading to race conditions, stale data, duplicated requests, and poor user experience.
This skill focuses on correctness, resilience, and user experience, not just making API calls work.
When to Use This Skill
- Connecting frontend apps (React, React Native, Vue, etc.) to backend APIs
- Integrating ML/AI endpoints (
/predict,/recommend) - Handling asynchronous data in UI
- Fixing stale data, flickering UI, or duplicate requests
- Designing scalable frontend API layers
Core Patterns
1. API Layer (Separation of Concerns)
Centralize API logic and normalize errors.
export class ApiError extends Error {
constructor(message, status, payload = null) {
super(message);
this.name = "ApiError";
this.status = status;
this.payload = payload;
}
}
export const apiClient = async (url, options = {}) => {
const res = await fetch(url, {
headers: { "Content-Type": "application/json" },
...options,
});
if (!res.ok) {
let payload = null;
try {
payload = await res.json();
} catch (_) {}
throw new ApiError(
payload?.message || "Request failed",
res.status,
payload
);
}
// handle empty responses safely (e.g. 204 No Content)
if (res.status === 204) return null;
const text = await res.text();
return text ? JSON.parse(text) : null;
};
2. Race-Safe State Management
Prevent stale responses from overwriting fresh data.
useEffect(() => {
let cancelled = false;
const load = async () => {
try {
setLoading(true);
setError(null);
const result = await getUser();
if (!cancelled) setData(result);
} catch (err) {
if (!cancelled) setError(err.message);
} finally {
if (!cancelled) setLoading(false);
}
};
load();
return () => {
cancelled = true;
};
}, []);
Use a cancellation flag for non-fetch async logic. For network requests, prefer AbortController.
3. Request Cancellation (AbortController)
Cancel in-flight requests to avoid memory leaks and stale updates.
useEffect(() => {
const controller = new AbortController();
const load = async () => {
try {
const data = await getUser({ signal: controller.signal });
setData(data);
} catch (err) {
if (err.name === "AbortError") return;
setError(err.message);
}
};
load();
return () => controller.abort();
}, [userId]);
4. Retry with Exponential Backoff
Retry only explicitly replay-safe operations and classified transient failures. The default performs one attempt. Do not classify arbitrary programming or parsing exceptions as network errors. Honor provider Retry-After and a total deadline in the real adapter; do not enable this simple backoff for rate-limit responses. The POST prediction example intentionally does not enable retries unless the backend contract independently guarantees replay safety.
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const fetchWithBackoff = async (fn, retries = 3, delay = 300, replaySafe = false) => {
try {
return await fn();
} catch (err) {
const isAbort = err.name === "AbortError";
const isHttpError = typeof err.status === "number";
const isNetworkFailure = err.code === "NETWORK_ERROR";
const isRetryable = replaySafe && !isAbort &&
(isNetworkFailure || (isHttpError && err.status >= 500));
if (retries <= 0 || !isRetryable) throw err;
const nextDelay = delay * 2 + Math.random() * 100;
await sleep(nextDelay);
return fetchWithBackoff(fn, retries - 1, nextDelay, replaySafe);
}
};
5. Debounced API Calls
Avoid excessive API calls (e.g., search inputs).
const useDebounce = (value, delay = 400) => {
const [debounced, setDebounced] = useState(value);
useEffect(() => {
const t = setTimeout(() => setDebounced(value), delay);
return () => clearTimeout(t);
}, [value, delay]);
return debounced;
};
6. Request Deduplication
Prevent duplicate API calls across components.
const inFlight = new Map();
…
FAQ
What is a 'race condition'?
It's when two or more actions happen at the same time, and the order in which they finish causes an unexpected or incorrect result.
Why cancel requests?
To prevent the application from showing outdated or broken information, especially if the user navigates away before the response arrives.
What is a 'retry strategy'?
It's a way to try an action again if it fails, waiting a bit longer each time, to handle temporary connection issues.
Details
Original description by the author
Production-ready patterns for integrating frontend applications with backend APIs, including race condition handling, request cancellation, retry strategies, error normalization, and UI state management.
Popularity
- GitHub stars
- 48k
- Ranking position
- #3047
- License
- MIT
- Updated
- 10/15/2026
Comments
- …
More skills from this repository
00-andruia-consultant
Helps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
sickn33/agentic-awesome-skills
007
Lets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
sickn33/agentic-awesome-skills
10-andruia-skill-smith
Helps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
sickn33/agentic-awesome-skills
20-andruia-niche-intelligence
Lets your agent create a summary about a specific industry. It's useful for understanding the context, rules, usage patterns, and risks of a project, using reliable sources.
sickn33/agentic-awesome-skills
Similar skills
angular-developer
Helps your agent create Angular code and give project structure advice. Useful for starting new projects, creating code parts, or improving performance and accessibility.
affaan-m/ECC
frontend-a11y
Helps your agent make web interfaces accessible to everyone. It ensures websites and apps work well with screen readers and keyboard navigation.
affaan-m/ECC
frontend-patterns
Has your agent apply modern patterns in frontend development. It optimizes performance, manages state, and follows best practices in React and Next.js.
affaan-m/ECC