@alistt69/create-api 0.1.5 → 0.1.6
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 +44 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,22 +7,56 @@
|
|
|
7
7
|
<h1>@alistt69/create-api</h1>
|
|
8
8
|
|
|
9
9
|
> **One helper. No extra.**
|
|
10
|
-
>
|
|
10
|
+
> A lightweight createApi inspired by **RTKQ** — with query, lazy query and mutation hooks, built-in cache utilities, stale data handling and a tiny, focused API.
|
|
11
11
|
|
|
12
12
|
[](https://www.npmjs.com/package/@alistt69/create-api)
|
|
13
13
|
[](https://nodejs.org/)
|
|
14
|
+
[](https://react.dev/)
|
|
14
15
|
[](./LICENSE)
|
|
15
16
|
[](https://github.com/alistt69/alistt69-create-api/actions/workflows/ci.yml)
|
|
16
17
|
</td>
|
|
17
18
|
</tr>
|
|
18
19
|
</table>
|
|
19
20
|
|
|
20
|
-
##
|
|
21
|
+
## ✨ Overview
|
|
22
|
+
|
|
23
|
+
`@alistt69/create-api` is a lightweight [RTK Query-inspired](https://redux-toolkit.js.org/rtk-query/overview) helper for React apps that need a clean createApi experience without Redux.
|
|
24
|
+
|
|
25
|
+
It provides query, lazy query and mutation hooks, cache helpers and stale data support in a compact API designed for everyday app needs.
|
|
26
|
+
|
|
27
|
+
## 🔧 What’s inside
|
|
28
|
+
|
|
29
|
+
| Feature | Purpose |
|
|
30
|
+
| -------------------- | ------------------------------------ |
|
|
31
|
+
| Query hooks | Fetch data with generated hooks |
|
|
32
|
+
| Lazy query hooks | Trigger queries manually when needed |
|
|
33
|
+
| Mutation hooks | Handle writes with generated hooks |
|
|
34
|
+
| Cache utils | Read and patch cached data manually |
|
|
35
|
+
| Stale time support | Reuse cached data before refetching |
|
|
36
|
+
| Keep unused data for | Control cache lifetime after unmount |
|
|
37
|
+
|
|
38
|
+
## 🎯 Why use it?
|
|
39
|
+
|
|
40
|
+
This package is specified for projects with no Redux.
|
|
41
|
+
|
|
42
|
+
It gives you a RTKQ-similar API model and developer experience, while staying smaller, simpler and focused on the most common data-fetching needs.
|
|
43
|
+
|
|
44
|
+
Do whatever you want and however you want with:
|
|
45
|
+
* generated hooks
|
|
46
|
+
* predictable cache behavior
|
|
47
|
+
* simple manual cache updates
|
|
48
|
+
* a focused API without a larger state layer
|
|
49
|
+
|
|
50
|
+
## 📦 Requirements
|
|
51
|
+
* Node.js 18 or higher
|
|
52
|
+
* React 16.8 or higher
|
|
53
|
+
|
|
54
|
+
## 🔥 Install
|
|
21
55
|
```bash
|
|
22
56
|
npm i @alistt69/create-api
|
|
23
57
|
```
|
|
24
58
|
|
|
25
|
-
##
|
|
59
|
+
## ⚡ Quick example
|
|
26
60
|
```typescript jsx
|
|
27
61
|
import { createApi } from '@alistt69/create-api';
|
|
28
62
|
|
|
@@ -58,7 +92,7 @@ const api = createApi({
|
|
|
58
92
|
});
|
|
59
93
|
```
|
|
60
94
|
|
|
61
|
-
## Usage
|
|
95
|
+
## 🛠️ Usage
|
|
62
96
|
```typescript jsx
|
|
63
97
|
function Post() {
|
|
64
98
|
const { data, isLoading } = api.useGetPostQuery('1');
|
|
@@ -74,17 +108,14 @@ function Post() {
|
|
|
74
108
|
}
|
|
75
109
|
```
|
|
76
110
|
|
|
77
|
-
## Cache utils
|
|
111
|
+
## ⚙️ Cache utils
|
|
78
112
|
``` typescript
|
|
79
113
|
api.util.getQueryData('getPost', '1');
|
|
80
114
|
api.util.setQueryData('getPost', '1', { id: '1', title: 'Local title' });
|
|
81
115
|
```
|
|
82
116
|
|
|
83
|
-
##
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
npm run build
|
|
89
|
-
npm pack
|
|
90
|
-
```
|
|
117
|
+
## 📄 License
|
|
118
|
+
|
|
119
|
+
MIT — free and open for everyone.
|
|
120
|
+
|
|
121
|
+
_See [License](./LICENSE)._
|