api-convention

Enforces Axios and TanStack Query patterns for API services and React Query hooks.

Updated Aug 19, 2026
One-click install
npx skills add https://github.com/homeslands/trend-ui --skill api-convention-homeslands
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-convention
Source: https://github.com/homeslands/trend-ui/tree/main/app/order-ui/.claude/skills/api-convention
Command: npx skills add https://github.com/homeslands/trend-ui --skill api-convention-homeslands

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Inconsistent API integration leads to duplicated auth logic, scattered query keys, and error handling bugs. This Skill ensures every API service, query hook, and mutation in the project follows the same established Axios and TanStack Query conventions. ## Core Features & Use Cases - HTTP Client Rules: Mandates importing the shared http client from @/utils, which auto-attaches Bearer tokens, refreshes expired tokens, and shows loading indicators. - Service Layer Pattern: Defines one file per domain in src/api/, with typed IApiResponse<T> returns, verb-matched function names, and no try/catch in the API layer. - React Query Integration: Standardizes centralized QUERYKEY constants, query hooks with enabled guards, mutations with cache invalidation, polling with refetchInterval, and pagination with keepPreviousData. - Use Case: When adding a new endpoint like fetching printer events, generate the service function in src/api/printer.ts, add a key to QUERYKEY, and create a typed hook in src/hooks/ that follows the project's mutation and invalidation pattern. ## Quick Start Create a new API service function and React Query hook for the notifications endpoint following the project conventions.

Frequently Asked Questions about api-convention

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create an API service function with Axios and TypeScript?

Create one function per endpoint in a domain file under src/api/, type the response as Promise<IApiResponse<T>>, and return response.data to unwrap the Axios wrapper. Name functions after the HTTP verb, such as getOrderBySlug or createOrder, and never add try/catch since React Query handles errors.

How do I write a React Query mutation hook with cache invalidation?

Use useMutation with a mutationFn calling the API service, then call queryClient.invalidateQueries with the relevant QUERYKEY in onSuccess. Global error toasts are handled by MutationCache in App.tsx, so only add onError for specific extra handling.

Should I use React Query or call API functions directly in components?

Always use a React Query hook from src/hooks/ rather than calling API functions directly in components. Hooks provide caching, loading states, automatic refetching, and integration with the global error handling configured in QueryCache and MutationCache.

How do I suppress the loading bar for background polling requests?

Pass doNotShowLoading: true in the Axios request config, using @ts-expect-error since it is not part of the standard AxiosRequestConfig type. This is the standard pattern for polling endpoints like kitchen orders that refetch on an interval.

Why should query keys be centralized instead of inline strings?

Centralized QUERYKEY constants in src/constants/query.ts prevent typos and make cache invalidation reliable across mutations and queries. Inline string arrays risk mismatched keys, which silently break invalidation and leave stale data on screen.