@djangocfg/api 1.4.18 → 1.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -20
- package/package.json +26 -3
package/README.md
CHANGED
|
@@ -1,29 +1,87 @@
|
|
|
1
1
|
# @djangocfg/api
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Auto-generated TypeScript API client with React hooks, SWR integration, and Zod validation for Django REST Framework backends
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@djangocfg/api)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
7
|
|
|
7
|
-
-
|
|
8
|
-
- Type-safe request/response handling
|
|
9
|
-
- Error handling utilities
|
|
8
|
+
**Part of [DjangoCFG](https://djangocfg.com)** — a modern Django framework for building production-ready SaaS applications. All `@djangocfg/*` packages are designed to work together, providing type-safe configuration, real-time features, and beautiful admin interfaces out of the box.
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
`@djangocfg/api` provides a fully type-safe API client automatically generated from your Django REST Framework OpenAPI schema. It includes React hooks powered by SWR for data fetching, Zod schemas for runtime validation, and fetcher functions for server-side usage.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- **Type-Safe API Calls** - Full TypeScript support with auto-generated types from OpenAPI
|
|
19
|
+
- **React Hooks** - SWR-powered hooks for seamless data fetching and caching
|
|
20
|
+
- **Zod Validation** - Runtime schema validation for API responses
|
|
21
|
+
- **Code Generation** - Automatic client generation from Django REST Framework schemas
|
|
22
|
+
- **Error Handling** - Built-in retry logic with p-retry
|
|
23
|
+
- **SSR Support** - Works with Next.js server components and API routes
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @djangocfg/api
|
|
29
|
+
# or
|
|
30
|
+
pnpm add @djangocfg/api
|
|
31
|
+
# or
|
|
32
|
+
yarn add @djangocfg/api
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
12
36
|
|
|
13
37
|
```tsx
|
|
14
|
-
import {
|
|
38
|
+
import { useUsers, createUser } from '@djangocfg/api';
|
|
39
|
+
|
|
40
|
+
function UserList() {
|
|
41
|
+
const { data, error, isLoading } = useUsers();
|
|
42
|
+
|
|
43
|
+
if (isLoading) return <div>Loading...</div>;
|
|
44
|
+
if (error) return <div>Error: {error.message}</div>;
|
|
15
45
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
46
|
+
return (
|
|
47
|
+
<ul>
|
|
48
|
+
{data?.map(user => (
|
|
49
|
+
<li key={user.id}>{user.name}</li>
|
|
50
|
+
))}
|
|
51
|
+
</ul>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
19
54
|
```
|
|
20
55
|
|
|
21
|
-
##
|
|
56
|
+
## API Reference
|
|
57
|
+
|
|
58
|
+
### Hooks
|
|
59
|
+
|
|
60
|
+
All generated hooks follow the pattern `use{Resource}` and return SWR response objects:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
const { data, error, isLoading, mutate } = useResource(params);
|
|
64
|
+
```
|
|
22
65
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
|
|
66
|
+
### Fetchers
|
|
67
|
+
|
|
68
|
+
For server-side usage or custom implementations:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
import { fetchUsers } from '@djangocfg/api/cfg/generated/fetchers';
|
|
72
|
+
|
|
73
|
+
const users = await fetchUsers({ page: 1, limit: 10 });
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Schemas
|
|
77
|
+
|
|
78
|
+
Zod schemas for validation:
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
import { UserSchema } from '@djangocfg/api/cfg/generated/schemas';
|
|
82
|
+
|
|
83
|
+
const validatedUser = UserSchema.parse(rawData);
|
|
84
|
+
```
|
|
27
85
|
|
|
28
86
|
## Configuration
|
|
29
87
|
|
|
@@ -33,10 +91,21 @@ Set API base URL via environment variable:
|
|
|
33
91
|
NEXT_PUBLIC_API_URL=http://localhost:8000
|
|
34
92
|
```
|
|
35
93
|
|
|
36
|
-
##
|
|
94
|
+
## Requirements
|
|
37
95
|
|
|
38
|
-
|
|
96
|
+
- Node.js >= 20.11.1
|
|
97
|
+
- React >= 19.1.0
|
|
98
|
+
- SWR >= 2.3.0
|
|
99
|
+
- Zod >= 4.0.10
|
|
39
100
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
101
|
+
## Documentation
|
|
102
|
+
|
|
103
|
+
Full documentation available at [djangocfg.com](https://djangocfg.com)
|
|
104
|
+
|
|
105
|
+
## Contributing
|
|
106
|
+
|
|
107
|
+
Issues and pull requests are welcome at [GitHub](https://github.com/markolofsen/django-cfg)
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT - see [LICENSE](./LICENSE) for details
|
package/package.json
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/api",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.19",
|
|
4
|
+
"description": "Auto-generated TypeScript API client with React hooks, SWR integration, and Zod validation for Django REST Framework backends",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"django",
|
|
7
|
+
"api-client",
|
|
8
|
+
"typescript",
|
|
9
|
+
"react-hooks",
|
|
10
|
+
"swr",
|
|
11
|
+
"zod",
|
|
12
|
+
"openapi",
|
|
13
|
+
"rest-api",
|
|
14
|
+
"code-generation",
|
|
15
|
+
"django-rest-framework",
|
|
16
|
+
"drf",
|
|
17
|
+
"type-safe"
|
|
18
|
+
],
|
|
4
19
|
"author": {
|
|
5
20
|
"name": "DjangoCFG",
|
|
6
21
|
"url": "https://djangocfg.com"
|
|
7
22
|
},
|
|
23
|
+
"homepage": "https://djangocfg.com",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/markolofsen/django-cfg.git",
|
|
27
|
+
"directory": "packages/api"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/markolofsen/django-cfg/issues"
|
|
31
|
+
},
|
|
8
32
|
"license": "MIT",
|
|
9
|
-
"description": "Auto-generated TypeScript API clients",
|
|
10
33
|
"type": "module",
|
|
11
34
|
"main": "./dist/index.cjs",
|
|
12
35
|
"module": "./dist/index.mjs",
|
|
@@ -68,7 +91,7 @@
|
|
|
68
91
|
"@types/node": "^22.15.3",
|
|
69
92
|
"@types/react": "19.2.2",
|
|
70
93
|
"@types/react-dom": "19.2.1",
|
|
71
|
-
"@djangocfg/typescript-config": "^1.4.
|
|
94
|
+
"@djangocfg/typescript-config": "^1.4.19",
|
|
72
95
|
"react": "^19.1.0",
|
|
73
96
|
"react-dom": "^19.1.0",
|
|
74
97
|
"tsup": "^8.5.0",
|