rest-api-integration
Skill2 starsChanged 4 months agoMITView on GitHub
Integrate third-party or internal REST APIs correctly from the frontend and server — typed fetch clients, error handling, retries, caching, and pagination. Use whenever the user is calling an external API, building an API client/SDK wrapper, integrating a third-party service, or asking how to structure API calls in a Next.js app.
- Reads credentials
In this repository22 other files it gives its agents.
- accessibility-a11ySkill
- design-system-tailwindSkill
- motion-design-toolkitSkill
- nextjs-architectureSkill
- react-component-engineeringSkill
- react-three-fiber-3dSkill
- responsive-mobile-firstSkill
- auth-authorizationSkill
- database-schema-designSkill
- form-validation-error-handlingSkill
- mern-stack-architectureSkill
- state-managementSkill
- landing-page-conversionSkill
- payment-gateway-integrationSkill
- saas-dashboard-adminSkill
- startup-mvp-developmentSkill
- ux-research-flow-designSkill
- visual-design-languageSkill
- ai-assisted-frontend-workflowSkill
- deployment-vercel-productionSkill
- performance-seo-optimizationSkill
- project-architecture-clean-codeSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Client-side fetch: only for public, unauthenticated endpoints or endpoints proxied through your own backend that don't need a secret.
- Very specific: line 40
Prefer cursor-based pagination (?cursor=...) over offset-based for anything with frequently-changing data (avoids skipped/duplicated items).
- Very specific: line 49
No response validation — trusting as type casts on external API responses
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
REST API Integration Skill
Where API calls belong
- Server-side by default (Server Component fetch, Server Action, or route handler) for anything using a secret API key — never expose third-party API keys to the client.
- Client-side fetch only for public, unauthenticated endpoints or endpoints proxied through your own backend that don't need a secret.
Typed client pattern
Wrap every external API in a small typed client instead of calling fetch ad hoc across the codebase:
// lib/api/stripe-client.ts (example shape, applies to any REST API)
async function apiFetch<T>(path: string, init?: RequestInit): Promise<T> {
const res = await fetch(`${BASE_URL}${path}`, {
...init,
headers: { Authorization: `Bearer ${process.env.API_SECRET}`, ...init?.headers },
});
if (!res.ok) throw new ApiError(res.status, await res.text());
return res.json();
}Validate the response shape with zod at the boundary (schema.parse(await res.json())) rather than trusting as Type casts — third-party APIs change without warning.
Caching & revalidation (Next.js fetch)
fetch(url, { next: { revalidate: 60, tags: ['products'] } }); // ISR-style caching
fetch(url, { cache: 'no-store' }); // always fresh, e.g. user-specific data
revalidateTag('products'); // call after a mutation to bust the cache on demandError handling & retries
- Distinguish error types: network failure, 4xx (client error — don't retry, surface to user), 5xx/timeout (transient — retry with backoff).
- Simple backoff: retry up to 3 times with exponential delay (e.g. 300ms, 900ms, 2700ms) only on 5xx/network errors, never on 4xx.
- Surface actionable errors to the UI (not raw stack traces) — map API error codes to user-facing messages centrally, not per call site.
Pagination
- Prefer cursor-based pagination (
?cursor=...) over offset-based for anything with frequently-changing data (avoids skipped/duplicated items). - For infinite scroll in React, use a library-agnostic pattern: fetch next cursor, append to state, disable further fetch when
hasMoreis false.
Rate limits
- Respect
Retry-Afterheaders; queue/backoff rather than hammering a rate-limited endpoint. - For high-volume server-to-server integrations, add a simple in-memory or Redis-backed rate limiter on your own proxy route if the third party doesn't provide one.
Anti-patterns to flag
- Third-party secret API keys used directly in client components (
NEXT_PUBLIC_*misuse) - No response validation — trusting
astype casts on external API responses - Retrying 4xx errors (client errors won't resolve by retrying)
- Duplicated fetch logic copy-pasted across components instead of a shared client
Example prompt this skill should trigger on
"Integrate the [X] third-party API to pull product data into our dashboard."
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

