reactive/data-client / .agents/skills/data-client-setup
data-client-setup
VerifiedInstall and set up @data-client/react or @data-client/vue in a project. Detects project type (NextJS, Expo, React Native, Vue, plain React) and protocol (REST, GraphQL, custom), then follows the bundled protocol-specific setup guide.
references/data-client-rest-setup/references/ky-migration.md
View on GitHub<!-- Generated by `yarn build:skills` from .agents/skills/data-client-rest-setup/references/ky-migration.md. Edit the source, not this file. -->
# Ky → @data-client/rest Migration
## Detection
- `"ky"` in `package.json` dependencies
- `import ky from 'ky'` or `import ky from 'ky/umd'` in source
Search patterns:
- `import.*from ['"]ky['"]` — import statements
- `ky\.create` — instance creation
- `ky\.(get|post|put|patch|delete|head)` — direct calls
## Migration Rules
### Basic instance → base class
```ts
// Before: ky instance
import ky from 'ky';
const api = ky.create({
prefixUrl: 'https://api.example.com',
headers: { Authorization: `Bearer ${token}` },
hooks: {
beforeRequest: [req => { /* ... */ }],
afterResponse: [(_req, _opts, res) => { /* ... */ }],
},
});
const users = await api.get('users').json<User[]>();
// After: RestEndpoint base class
import { RestEndpoint, RestGenerics } from '@data-client/rest';
class ApiEndpoint<O extends RestGenerics = any> extends RestEndpoint<O> {
urlPrefix = 'https://api.example.com';
getHeaders(headers: HeadersInit) {
return {
...headers,
Authorization: `Bearer ${token}`,
};
}
}
export const getUsers = new ApiEndpoint({
path: '/users',
schema: [User],
});
```
### Key conversions
| Ky pattern | RestEndpoint equivalent |
|------------|----------------------|
| `prefixUrl` | `urlPrefix` |
| `headers` option | `getHeaders()` |
| `hooks.beforeRequest` | `getHeaders()` or `getRequestInit()` |
| `hooks.afterResponse` | `process()` in the base class |
| `hooks.beforeError` | `fetchResponse()` override |
| `ky.create()` shared options | Base class overrides |
| `.json<T>()` | Automatic — RestEndpoint parses JSON by default |
| `HTTPError` | `NetworkError` |
| `searchParams` option | `searchParams` type on endpoint |
| `timeout` | `AbortSignal.timeout(ms)` in a `getRequestInit()` override, so each request gets its own timer ([Timeout](axios-migration.md#timeout)); a `signal` option would start one timer when the endpoint is created |
| `retry` (ky retries by default) | Delete it: Data Client has no retry loop, and a failed request is fetched again when a component next needs it after `errorExpiryLength` (default 1 second). Tell the user that automatic retries are dropped |
| `credentials` | `getRequestInit()` override |
### Hooks → lifecycle methods
```ts
// Before: ky hooks
const api = ky.create({
hooks: {
beforeRequest: [
request => {
request.headers.set('X-Request-Id', generateId());
},
],
afterResponse: [
(_request, _options, response) => {
logResponse(response.status);
return response;
},
],
beforeError: [
error => {
reportError(error);
return error;
},
],
},
});
// After: lifecycle methods
class ApiEndpoint<O extends RestGenerics = any> extends RestEndpoint<O> {
getHeaders(headers: HeadersInit) {
return {
...headers,
'X-Request-Id': generateId(),
};
}
async parseResponse(response: Response) {
logResponse(response.status);
return super.parseResponse(response);
}
async fetchResponse(input: RequestInfo, init: RequestInit) {
try {
return await super.fetchResponse(input, init);
} catch (error) {
reportError(error);
throw error;
}
}
}
```
### Error handling
```ts
// Before
import { HTTPError } from 'ky';
try { ... } catch (err) {
if (err instanceof HTTPError) {
const body = await err.response.json();
console.log(err.response.status, body);
}
}
// After
import { NetworkError } from '@data-client/rest';
try { ... } catch (err) {
if (err instanceof NetworkError) {
console.log(err.status);
const body = await err.response.json();
}
}
```
## Reference
- [RestEndpoint API](https://dataclient.io/rest/api/RestEndpoint) — lifecycle methods reference
- [NetworkError](https://dataclient.io/rest/api/RestEndpoint#fetchResponse) — error class
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |