fetchwire 1.0.0 → 1.0.1
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 +7 -26
- package/package.json +8 -1
package/README.md
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
# fetchwire
|
|
2
2
|
|
|
3
|
-
A lightweight, focused API fetching library for React and React Native applications.
|
|
3
|
+
A lightweight, focused API fetching library for **React and React Native** applications.
|
|
4
4
|
|
|
5
5
|
**fetchwire** wraps the native `fetch` API in a global configuration layer. It is designed to make it easy to:
|
|
6
|
-
|
|
7
6
|
- Centralize your API base URL, auth token, and common headers.
|
|
8
|
-
- Handle errors consistently
|
|
7
|
+
- Handle errors consistently.
|
|
9
8
|
|
|
10
9
|
### When to use fetchwire
|
|
11
10
|
- **React / React Native apps** that:
|
|
12
11
|
- Want a **simple**, centralized way to call HTTP APIs.
|
|
13
12
|
- Prefer plain hooks over a heavier state management or query library.
|
|
14
13
|
- Need basic tag-based invalidation without a full cache layer.
|
|
15
|
-
- Handle errors in a consistent way across screens.
|
|
16
14
|
|
|
17
15
|
### When not to use fetchwire
|
|
18
16
|
- Consider a more full-featured solution (e.g. TanStack Query / React Query, SWR, RTK Query) if:
|
|
@@ -29,28 +27,15 @@ If you find **fetchwire** helpful and want to support its development, you can b
|
|
|
29
27
|
Your support helps maintain the library and keep it up to date!
|
|
30
28
|
|
|
31
29
|
## Features
|
|
32
|
-
|
|
33
|
-
- **Global configuration with `initWire`**
|
|
30
|
+
- **Global API fetching configuration `initWire`**
|
|
34
31
|
- Configure `baseUrl`, default headers, and how to read the auth token.
|
|
35
32
|
- Optionally register global interceptors for 401/403/other errors.
|
|
36
|
-
-
|
|
37
|
-
|
|
38
|
-
- **Typed HTTP wrapper with `wireApi`**
|
|
39
|
-
- Thin wrapper around `fetch` that:
|
|
40
|
-
- Appends the endpoint to a global `baseUrl`.
|
|
41
|
-
- Adds auth headers from `getToken`.
|
|
42
|
-
- Merges default and per-request headers.
|
|
43
|
-
- Converts server/network errors into a typed `ApiError`.
|
|
33
|
+
- Converts server/network errors into a typed `ApiError`.
|
|
44
34
|
|
|
45
|
-
- **React hooks for
|
|
35
|
+
- **React hooks for data fetching and mutation with Tag-based invalidation**
|
|
46
36
|
- **`useFetchFn<T>`** for data fetching
|
|
47
37
|
- **`useMutationFn<T>`** for mutations
|
|
48
|
-
|
|
49
|
-
- **Tag-based invalidation**
|
|
50
|
-
- `useFetchFn` can subscribe to **tags**.
|
|
51
|
-
- `useMutationFn` can **invalidate tags** after a successful mutation.
|
|
52
|
-
- This gives you a simple, explicit way to refetch related data without a complex cache layer.
|
|
53
|
-
|
|
38
|
+
- With a simple, explicit way to refetch related data through tags
|
|
54
39
|
---
|
|
55
40
|
|
|
56
41
|
## Installation
|
|
@@ -64,8 +49,6 @@ pnpm add fetchwire
|
|
|
64
49
|
```
|
|
65
50
|
|
|
66
51
|
### Peer expectations
|
|
67
|
-
|
|
68
|
-
- React or React Native project using function components and hooks.
|
|
69
52
|
- TypeScript is recommended but not required.
|
|
70
53
|
- For React Native / Expo, make sure the global `fetch` is available (default in modern RN/Expo).
|
|
71
54
|
|
|
@@ -407,7 +390,7 @@ You can also read `error` directly from `useFetchFn` state if you want to render
|
|
|
407
390
|
|
|
408
391
|
---
|
|
409
392
|
|
|
410
|
-
##
|
|
393
|
+
## API Reference
|
|
411
394
|
|
|
412
395
|
### `initWire(config)`
|
|
413
396
|
|
|
@@ -464,8 +447,6 @@ function getWireConfig(): WireConfig;
|
|
|
464
447
|
|
|
465
448
|
---
|
|
466
449
|
|
|
467
|
-
## API Reference
|
|
468
|
-
|
|
469
450
|
### `wireApi<T>(endpoint, options?)`
|
|
470
451
|
|
|
471
452
|
```ts
|
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fetchwire",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A lightweight, focused API fetching library for React and React Native applications.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/chuhaiphu/fetchwire.git"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"provenance": true
|
|
11
|
+
},
|
|
5
12
|
"main": "./dist/index.js",
|
|
6
13
|
"module": "./dist/index.mjs",
|
|
7
14
|
"types": "./dist/index.d.ts",
|