ajyadav013/claude-kit/api-integration
Claude Code and agent skill by ajyadav013/claude-kit
- community
Checking that the SKILL.md file is still in the repository.
Wire the app to a backend API — data fetching, caching, error handling, loading states. Use when connecting to an endpoint, adding a fetch layer, or fixing API error and loading behaviour. React-query detail lives in tanstack-react-query-patterns.
Install
npx vskill@latest install ajyadav013/claude-kit/api-integrationSKILL.md
The same SKILL.md was published earlier as ajyadav013/claude-kit/api-integration.
Integrate API for: $ARGUMENTS.
Steps
- Identify the API: Determine the endpoint(s), HTTP method(s), request/response shapes, and authentication requirements for $ARGUMENTS.
- Define types: Create typed interfaces for request and response payloads. Co-locate types with the API client module according to the project's conventions.
```typescript // TypeScript example export interface GetItemsParams { page: number; limit: number; status?: 'open' | 'resolved' | 'escalated'; }
export interface ItemResponse { data: Item[]; total: number; page: number; } ```
```python # Python example (Pydantic) from pydantic import BaseModel
class GetItemsParams(BaseModel): page: int limit: int status: str | None = None
class ItemResponse(BaseModel): data: list[Item] total: int page: int ```
- Create API client functions: Place in the project's designated API layer as pure async functions. Use the project's HTTP client.
```typescript // TypeScript example import { httpClient } from '@/lib/httpClient'; import type { GetItemsParams, ItemResponse } from './types/items';
export async function getItems(params: GetItemsParams): Promise<ItemResponse> { const { data } = await httpClient.get<ItemResponse>('/items', { params }); return data; }
export async function resolveItem(id: string, resolution: string): Promise<void> { await httpClient.post(/items/${encodeURIComponent(id)}/resolve, { resolution }); } ```
```python # Python example (httpx) import httpx from .schemas import GetItemsParams, ItemResponse
async def get_items(params: GetItemsParams) -> ItemResponse: async with httpx.AsyncClient() as client: response = await client.get('/items', params=params.model_dump()) return ItemResponse.model_validate(response.json())
async def resolve_item(id: str, resolution: str) -> None: async with httpx.AsyncClient() as client: await client.post(f'/items/{id}/resolve', json={'resolution': resolution}) ```
- Create data-fetching hooks/functions: Wrap API calls with the project's caching/state management layer.
### Query Pattern (React Query example) ```typescript import { useQuery } from '@tanstack/react-query'; import { getItems } from '@/api/items'; import type { GetItemsParams } from '@/api/types/items';
export const itemKeys = { all: ['items'] as const, lists: () => [...itemKeys.all, 'list'] as const, list: (params: GetItemsParams) => [...itemKeys.lists(), params] as const, details: () => [...itemKeys.all, 'detail'] as const, detail: (id: string) => [...itemKeys.details(), id] as const, };
export function useItems(params: GetItemsParams) { return useQuery({ queryKey: itemKeys.list(params), queryFn: () => getItems(params), staleTime: 5 60 1000, // 5 minutes placeholderData: keepPreviousData, }); } ```
### Mutation Pattern (React Query example) ```typescript import { useMutation, useQueryClient } from '@tanstack/react-query'; import { resolveItem } from '@/api/items';
export function useResolveItem() { const queryClient = useQueryClient();
return useMutation({ mutationFn: ({ id, resolution }: { id: string; resolution: string }) => resolveItem(id, resolution), onSuccess: () => { queryClient.invalidateQueries({ queryKey: itemKeys.all }); }, }); } ```
### Alternative: Service Layer Pattern (backend or Vue/Angular) ```python # Python service layer from .repository import ItemRepository from .schemas import GetItemsParams, ItemResponse
class ItemService: def __init__(self, repo: ItemRepository): self.repo = repo
async def get_items(self, params: GetItemsParams) -> ItemResponse: items = await self.repo.find_all(params) total = await self.repo.count(params) return ItemResponse(data=items, total=total, page=params.page) ```
- Validate responses at the boundary: Use a validation library to ensure API responses match expected shapes.
```typescript // TypeScript with Zod import { z } from 'zod';
const itemResponseSchema = z.object({ data: z.array(itemSchema), total: z.number(), page: z.number(), });
export async function getItems(params: GetItemsParams) { const { data } = await httpClient.get('/items', { params }); return itemResponseSchema.parse(data); } ```
```python # Python with Pydantic (validation built-in) from pydantic import BaseModel, field_validator
class ItemResponse(BaseModel): data: list[Item] total: int page: int
@field_validator('total') @classmethod def total_non_negative(cls, v: int) -> int: if v < 0: raise ValueError('total must be non-negative') return v ```
- Use in components/views: Follow the loading/empty/error state pattern.
```tsx // React example function ItemList() { const { data, isLoading, error } = useItems({ page: 1, limit: 20 });
if (isLoading) return <Spinner />; if (error) return <EmptyState title="Failed to load items" />; if (!data?.data.length) return <EmptyState title="No items found" />;
return ( <div className="space-y-3"> {data.data.map((item) => ( <ItemCard key={item.id} item={item} /> ))} </div> ); } ```
```python # Python (FastAPI) example from fastapi import APIRouter, Depends, HTTPException, status
@router.get('/items', response_model=ItemResponse) async def list_items( params: GetItemsParams = Depends(), service: ItemService = Depends(), ) -> ItemResponse: try: return await service.get_items(params) except Exception as e: raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail='Failed to load items' ) ```
- Verify: Run the project's linter, type checker, and build to confirm all checks pass.
Data-Fetching Conventions
Cache Key Factory
Every feature should have a key factory object for consistent cache management (applies to client-side caching libraries like TanStack Query, SWR, Apollo):
Stale Time Defaults (Client-Side Caching)
| Data Type | Stale Time | Rationale | |
|---|---|---|---|
| Reference data (categories, roles) | 30 minutes | Rarely changes | |
| Dashboard KPIs | 5 minutes | Moderate freshness | |
| Real-time feeds (notifications, alerts) | 1 minute | Needs frequent updates | |
| User-specific (preferences) | Infinity | Only changes on mutation |
Error Handling
- Use the data-fetching layer's built-in error state — avoid wrapping in try/catch at the component level
- Global error handler for auth errors (401 → redirect to login)
- Show empty/error state UI for query failures
- Show toast/notification for mutation failures
Optimistic Updates (Client-Side)
Use for operations where the user expects instant feedback:
Directory Structure
Adapt to your project's conventions. Common patterns:
Frontend (React/Vue/Angular)
Backend (Python/Node/Go/etc.)
Key rules:
- API client functions (plain async) live in the project's designated API layer
- Data-fetching hooks/wrappers live alongside the module or in a dedicated hooks folder
- Key factories can be co-located or centralized depending on the project's conventions
- Validation happens at system boundaries (API responses in frontend, request payloads in backend)
Common Patterns by Stack
React + TanStack Query
- Query hooks:
useQueryfor reads,useMutationfor writes - Key factories for cache management
invalidateQueriesafter mutationsplaceholderData: keepPreviousDatafor pagination
Vue + Pinia
- API functions in composables (
useItems) - Pinia store for caching if needed
- Loading/error state in composable return
Angular + RxJS
- API functions return Observables
- Service layer manages HTTP calls
catchErrorfor error handlingshareReplayfor caching
Backend (FastAPI/Express/Spring Boot)
- Repository pattern for data access
- Service layer for business logic
- Route handlers delegate to services
- Typed request/response schemas
Deterministic Testing Against External APIs (record-replay)
Tests that hit a live third-party API are slow, flaky, rate-limited, and fail when you're offline or the vendor has an incident — yet hand-written mocks drift out of sync with the real contract and quietly stop reflecting it. The record-replay pattern gets both fidelity and determinism:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/api-integration/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ajyadav013/claude-kit/api-integration)