reactive/data-client / .agents/skills/data-client-rest-setup
data-client-rest-setup
VerifiedSet up and migrate to @data-client/rest for REST APIs. Detects existing HTTP patterns (axios, fetch, ky, superagent, got) and migrates them. Creates custom RestEndpoint base class with common behaviors. Use when adopting @data-client/rest in a new or existing project.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 7.5 KB |
| evals/evals.json | config | 2.8 KB |
| references.json | config | 386 B |
| references/RestEndpoint.md | markdown | 45.2 KB |
| references/RestEndpoint.vue.md | markdown | 46.1 KB |
| references/auth.md | markdown | 9.4 KB |
| references/auth.vue.md | markdown | 9.7 KB |
| references/axios-migration.md | markdown | 25.4 KB |
| references/axios-migration.vue.md | markdown | 25.5 KB |
| references/django.md | markdown | 2.3 KB |
| references/fetch-migration.md | markdown | 3.8 KB |
| references/got-migration.md | markdown | 4.3 KB |
| references/hookifyResource.md | markdown | 6.0 KB |
| references/hookifyResource.vue.md | markdown | 6.3 KB |
| references/ky-migration.md | markdown | 3.8 KB |
| references/resource.md | markdown | 27.0 KB |
| references/resource.vue.md | markdown | 27.1 KB |
| references/superagent-migration.md | markdown | 4.0 KB |
references/fetch-migration.md
View on GitHub# Raw fetch → @data-client/rest Migration
## Detection
Look for direct `fetch()` calls or thin wrappers around fetch in the codebase:
- `fetch(` calls with REST-style URLs (`/api/`, `/users/`, etc.)
- Custom wrapper functions that call `fetch` internally
- No HTTP client library in `package.json`
Search patterns:
- `\bfetch\(` — direct fetch calls
- `new Request\(` — Request object construction
- `\.json\(\)` — response parsing (common in fetch wrappers)
## Migration Rules
Convert `fetch()` call sites to `RestEndpoint`:
```ts
// Before: raw fetch wrapper
async function getUsers(token: string): Promise<User[]> {
const res = await fetch('https://api.example.com/users', {
headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
}
// After: RestEndpoint (auth moves to base class)
import { RestEndpoint } from '@data-client/rest';
import { User } from './User';
export const getUsers = new RestEndpoint({
urlPrefix: 'https://api.example.com',
path: '/users',
schema: [User],
});
```
### Key conversions
| fetch pattern | RestEndpoint equivalent |
|---------------|----------------------|
| `headers` option | `getHeaders()` on base class |
| `res.ok` / status checks | Automatic — throws `NetworkError` on non-2xx |
| `res.json()` | Automatic — `parseResponse()` defaults to JSON |
| Base URL string concatenation | `urlPrefix` on base class |
| Query string building (`URLSearchParams`, template literals) | `searchParams` type + `searchToString()` override |
| `method: 'POST'` | `method` option on RestEndpoint |
| `body: JSON.stringify(data)` | Pass object directly — RestEndpoint serializes automatically |
| `credentials: 'include'` | `getRequestInit()` override on base class |
| `AbortController` / `signal` | `endpoint.extend({ signal })` for that one request ([Cancellation](axios-migration.md#cancellation)); a `signal` set when the endpoint is created aborts all of its requests |
### Fetch wrappers with shared config
```ts
// Before: custom fetch wrapper
function apiFetch(path: string, options?: RequestInit) {
return fetch(`${BASE_URL}${path}`, {
...options,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${getToken()}`,
...options?.headers,
},
});
}
const res = await apiFetch('/users');
const users = await res.json();
// After: base class captures shared config
class ApiEndpoint<O extends RestGenerics = any> extends RestEndpoint<O> {
urlPrefix = BASE_URL;
getHeaders(headers: HeadersInit) {
return {
...headers,
Authorization: `Bearer ${getToken()}`,
};
}
}
export const getUsers = new ApiEndpoint({
path: '/users',
schema: [User],
});
```
### POST / mutation patterns
```ts
// Before
async function createUser(data: UserInput): Promise<User> {
const res = await fetch('https://api.example.com/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
});
return res.json();
}
// After
export const createUser = new RestEndpoint({
path: '/users',
method: 'POST',
schema: User,
});
```
### Error handling
```ts
// Before
if (!res.ok) {
const body = await res.json();
throw new Error(body.message);
}
// After — RestEndpoint throws NetworkError on non-2xx
import { NetworkError } from '@data-client/rest';
try { ... } catch (err) {
if (err instanceof NetworkError) {
console.log(err.status); // HTTP status code
const body = await err.response.json();
console.log(body.message);
}
}
```
## Reference
- [RestEndpoint API](https://dataclient.io/rest/api/RestEndpoint) — lifecycle methods reference
- [NetworkError](https://dataclient.io/rest/api/RestEndpoint#fetchResponse) — error class
- [Authentication guide](https://dataclient.io/rest/guides/auth) — token and cookie patterns
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |