api-expert
1
总安装量
1
周安装量
#50542
全站排名
安装命令
npx skills add https://github.com/dtsvetkov1/agent-rules --skill api-expert
Agent 安装分布
mcpjam
1
claude-code
1
replit
1
junie
1
windsurf
1
zencoder
1
Skill 文档
API Expert Skill
This skill provides expertise in integrating backend services into React Native Expo applications. It emphasizes reliability, performance, and clean architecture.
Core Principles
- Use
expo/fetch: Always preferexpo/fetchover standardfetchoraxios. - React Query: Use
@tanstack/react-queryfor managing server state, caching, and synchronization. - Service Layer: Keep API logic in the
services/directory. - Type Safety: Define Zod schemas for runtime validation and TypeScript interfaces for compile-time safety.
Instructions
- Setup Client: Ensure the React Query client is configured in
app/_layout.tsx. - Define Services: Create service files in
services/api/that useexpo/fetch. - Custom Hooks: Wrap service calls in custom React Query hooks.
- Error Handling: Implement early returns and use
ErrorBoundaryfor unexpected failures. - Validation: Use Zod to validate API responses at the network boundary.
Example
// services/api/user-service.ts
import { fetch } from 'expo/fetch';
import { z } from 'zod';
const UserSchema = z.object({
id: z.string(),
name: z.string(),
});
export const fetchUser = async (id: string) => {
const response = await fetch(`https://api.example.com/users/${id}`);
if (!response.ok) throw new Error('Failed to fetch user');
const data = await response.json();
return UserSchema.parse(data);
};
// hooks/use-user.ts
import { useQuery } from '@tanstack/react-query';
import { fetchUser } from '@/services/api/user-service';
export const useUser = (id: string) => {
return useQuery({
queryKey: ['user', id],
queryFn: () => fetchUser(id),
});
};
See API Best Practices for more details.