@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.
Files changed (2) hide show
  1. package/README.md +89 -20
  2. package/package.json +26 -3
package/README.md CHANGED
@@ -1,29 +1,87 @@
1
1
  # @djangocfg/api
2
2
 
3
- Type-safe API client for backend integration.
3
+ > Auto-generated TypeScript API client with React hooks, SWR integration, and Zod validation for Django REST Framework backends
4
4
 
5
- ## What's Inside
5
+ [![npm version](https://img.shields.io/npm/v/@djangocfg/api.svg)](https://www.npmjs.com/package/@djangocfg/api)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6
7
 
7
- - Auto-generated TypeScript clients
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
- ## Usage
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 { apiClient } from '@djangocfg/api';
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
- // Make API calls
17
- const response = await apiClient.get('/endpoint');
18
- const data = await apiClient.post('/endpoint', { body });
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
- ## Features
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
- - **Type Safety** - Full TypeScript support
24
- - **Auto-generated** - Clients generated from OpenAPI spec
25
- - **Error Handling** - Consistent error responses
26
- - **Authentication** - Token management built-in
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
- ## Generation
94
+ ## Requirements
37
95
 
38
- To regenerate clients from OpenAPI spec:
96
+ - Node.js >= 20.11.1
97
+ - React >= 19.1.0
98
+ - SWR >= 2.3.0
99
+ - Zod >= 4.0.10
39
100
 
40
- ```bash
41
- pnpm generate
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.18",
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.18",
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",