frontend/integrating-api/SKILL.md
Implement a type-safe API client using TanStack Query and Axios/Fetch to handle data fetching, caching, and server state.
npx skillsauth add 7a336e6e/skills integrating-apiInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Establish a robust, type-safe communication layer between frontend and backend that handles loading states, errors, caching, and data synchronization seamlessly.
Create a configured Axios instance or Fetch wrapper.
// src/lib/api.ts
import axios from 'axios';
export const api = axios.create({
baseURL: import.meta.env.VITE_API_URL,
headers: {
'Content-Type': 'application/json',
},
});
api.interceptors.response.use(
(response) => response,
(error) => {
// Handle global errors (401, 500)
return Promise.reject(error);
}
);
Abstract data fetching into custom hooks. Do not fetch directly in components.
// src/features/users/api/useUser.ts
import { useQuery } from '@tanstack/react-query';
import { api } from '@/lib/api';
import { User } from '@/types';
const getUser = async (id: string): Promise<User> => {
const { data } = await api.get(`/users/${id}`);
return data;
};
export const useUser = (id: string) => {
return useQuery({
queryKey: ['user', id],
queryFn: () => getUser(id),
enabled: !!id,
});
};
Use useMutation for updates/creates.
export const useCreateUser = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (newUser: CreateUserDto) => api.post('/users', newUser),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['users'] });
},
});
};
Handle these explicitly in the UI.
const { data, isLoading, error } = useUser(userId);
if (isLoading) return <Spinner />;
if (error) return <ErrorMessage message={error.message} />;
['resource', id]) for proper cache invalidation.useEffect for data fetching. It leads to race conditions and waterfall requests.src/lib/api.ts (client setup)src/features/*/api/*.ts (hooks and fetchers)../../backend/building-api-routes/SKILL.md (Defines the API contract)../managing-state/SKILL.mddevelopment
Implement features using the Red-Green-Refactor cycle to ensure testability and correctness from the start.
data-ai
Manage the `tasks.md` ledger with strict locking and collision avoidance protocols to allow multiple agents to work in parallel safely.
development
The git-workflow skill defines branching conventions, commit message formats, and pull request standards that all agents must follow for consistent version control.
development
The environment-config skill standardizes how agents manage environment variables, secrets, and application configuration across local development and deployed environments.