Skip to content
Back to skills

Api Integration

ASecurity

Provides frontend API integration patterns for a standard fetch layer, loading and error states, and optimistic updates; use when connecting a component to a REST API or implementing optimistic updates.

  • 19 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 19, 2026
ai-agentsapifrontend

Works with

  • cli
  • api

Security analysis

A100/100

Scanned October 19, 2026

npx -y skills add sawrus/agent-guides --skill api-integration --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Api Integration?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Api Integration
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sawrus-api-integration/badge)](https://www.skillsdirectory.com/skills/sawrus-api-integration)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: api-integration
description: "Provides frontend API integration patterns for a standard fetch layer, loading and error states, and optimistic updates; use when connecting a component to a REST API or implementing optimistic updates."
---

# Skill: API Integration Patterns

## When to load

When connecting a component to a REST API, handling loading/error states, or implementing optimistic updates.

## Standard Fetch Layer

```ts
const apiClient = {
  get: async <T>(path: string, options?: RequestInit): Promise<T> => {
    const res = await fetch(`${import.meta.env.VITE_API_URL}${path}`, {
      ...options,
      headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer ${getToken()}`,
        ...options?.headers,
      },
    });
    if (!res.ok) throw new ApiError(res.status, await res.json());
    return res.json();
  },
};
```

## Loading & Error States

```tsx
const UserList = () => {
  const { data, isLoading, isError, error } = useQuery({
    queryKey: ['users'],
    queryFn: () => apiClient.get<User[]>('/users'),
  });

  if (isLoading) return <UserListSkeleton />;
  if (isError) return <ErrorMessage message={error.message} />;

  return <ul>{data.map(user => <UserItem key={user.id} user={user} />)}</ul>;
};
```

## Optimistic Updates

```tsx
const mutation = useMutation({
  mutationFn: (id: string) => apiClient.delete(`/todos/${id}`),
  onMutate: async (id) => {
    await queryClient.cancelQueries({ queryKey: ['todos'] });
    const previous = queryClient.getQueryData<Todo[]>(['todos']);
    queryClient.setQueryData<Todo[]>(['todos'], old => old?.filter(t => t.id !== id));
    return { previous };
  },
  onError: (_err, _id, context) => {
    queryClient.setQueryData(['todos'], context?.previous);
  },
  onSettled: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
});
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.