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/django.md
View on GitHub<!-- Generated by `yarn build:skills` from docs/rest/guides/django.md (react). Edit the source doc, not this file. -->
# Django Integration
## Cookie Auth + CSRF
Django add protection against Cross Site Request Forgery, by [requiring the 'X-CSRFToken' header in requests](https://docs.djangoproject.com/en/5.0/howto/csrf/#using-csrf-protection-with-ajax).
Additionally Django's authentication uses [cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies), so we need to send credentials [fetch credentials](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#sending_a_request_with_credentials_included). If you use
an auth type other than the default 'django.contrib.auth', see [authentication guide](./auth.md) for more examples.
```ts title="getCookie"
export default function getCookie(name): string {
let cookieValue = '';
if (document.cookie && document.cookie != '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
```
```ts title="DjangoEndpoint"
import { RestEndpoint, type RestGenerics } from '@data-client/rest';
import getCookie from './getCookie';
export default class DjangoEndpoint<
O extends RestGenerics = any,
> extends RestEndpoint<O> {
async getRequestInit(body: any): Promise<RequestInit> {
return {
...(await super.getRequestInit(body)),
credentials: 'same-origin',
};
}
getHeaders(headers: HeadersInit) {
if (this.method === 'GET') return headers;
return {
...headers,
'X-CSRFToken': getCookie('csrftoken'),
};
}
}
```
```ts title="MyResource" {15}
import { resource, Entity } from '@data-client/rest';
import DjangoEndpoint from './DjangoEndpoint';
class MyEntity extends Entity {
id = '';
title = '';
}
export const MyResource = resource({
path: '/my/:id',
schema: MyEntity,
Endpoint: DjangoEndpoint,
});
```
```ts title="Usage" column
import { MyResource } from './MyResource';
MyResource.partialUpdate({ id: 1 }, { title: 'Signing in with cookies' });
```
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 |