tanstack-fetch 1.0.2 → 1.0.3
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 +66 -7
- package/package.json +29 -5
package/README.md
CHANGED
|
@@ -1,21 +1,63 @@
|
|
|
1
1
|
# tanstack-fetch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**TypeScript HTTP / fetch client for TanStack Query (React Query)** — built for Next.js SSR, auth interceptors, SSE streams, and multipart file upload. A tiny (~3.5KB gzip), tree-shakeable alternative to axios when your `queryFn` / `mutationFn` just needs a typed `fetch` wrapper.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/tanstack-fetch)
|
|
6
|
+
[](https://www.npmjs.com/package/tanstack-fetch)
|
|
7
|
+
[](https://bundlephobia.com/package/tanstack-fetch)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
[](https://nodejs.org)
|
|
10
|
+
[](https://www.typescriptlang.org/)
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install tanstack-fetch
|
|
14
|
+
# or
|
|
15
|
+
pnpm add tanstack-fetch
|
|
16
|
+
# or
|
|
17
|
+
yarn add tanstack-fetch
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Node 18+ (native `fetch`). Works in the browser, Node, and the Edge runtime.
|
|
21
|
+
|
|
22
|
+
> **Not an official TanStack package** — designed to match the `@tanstack/react-query` mental model (`throw` on HTTP errors, pass `signal`, typed data).
|
|
23
|
+
|
|
24
|
+
### Who is this for?
|
|
25
|
+
|
|
26
|
+
- Apps using **TanStack Query / React Query** that need a shared HTTP client for `queryFn` and `mutationFn`
|
|
27
|
+
- **Next.js** (App Router) SSR that must forward cookies / auth headers to your API
|
|
28
|
+
- Teams wanting a **lightweight axios / ky / ofetch alternative** with interceptors, retries, SSE, and upload progress — without a large HTTP stack
|
|
29
|
+
|
|
30
|
+
### Features at a glance
|
|
31
|
+
|
|
32
|
+
- Typed `get` / `post` / `put` / `patch` / `delete` / `upload` → `Promise<T>`
|
|
33
|
+
- Throws `FetchError` by default (TanStack Query–friendly); optional `FetchResult` union
|
|
34
|
+
- `AbortSignal` + timeout, Bearer auth, 401 / 403 / 404 / 5xx handlers
|
|
35
|
+
- Named interceptors (retry, short-circuit mocks, per-request eject)
|
|
36
|
+
- SSR cookie / header forwarding (`ssr-forward` plugin)
|
|
37
|
+
- Optional **SSE** over `fetch` streams (`tanstack-fetch/sse`)
|
|
38
|
+
- Multipart **file upload** + `onUploadProgress` (browser)
|
|
39
|
+
- Optional React `FetchProvider` / `useFetch` / `useSse`
|
|
40
|
+
- OpenAPI → TypeScript client CLI
|
|
4
41
|
|
|
5
42
|
| Import | What you get | Typical gzip |
|
|
6
43
|
| --- | --- | --- |
|
|
7
|
-
| `tanstack-fetch` | HTTP only (`get/post/…`) | **~3.5KB** |
|
|
44
|
+
| `tanstack-fetch` | HTTP only (`get/post/upload/…`) | **~3.5KB** |
|
|
8
45
|
| `tanstack-fetch/sse` | + `api.sse()` | **~4.7KB** |
|
|
9
46
|
| `tanstack-fetch/plugins` | plugin factories | **~0.9KB** |
|
|
10
47
|
| `tanstack-fetch/react` | `FetchProvider` / hooks (peer: core) | **~1KB** |
|
|
11
48
|
|
|
12
|
-
|
|
13
|
-
npm install tanstack-fetch
|
|
14
|
-
```
|
|
49
|
+
### Compared to axios, ky, ofetch
|
|
15
50
|
|
|
16
|
-
|
|
51
|
+
| Need | `tanstack-fetch` |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| Drop into TanStack Query `queryFn` | Yes — returns data, throws `FetchError`, takes `signal` |
|
|
54
|
+
| Next.js SSR cookie forwarding | Built-in `ssr-forward` plugin |
|
|
55
|
+
| Interceptors without axios weight | Named, ordered, ejectable plugins |
|
|
56
|
+
| SSE with Authorization headers | `tanstack-fetch/sse` (fetch streams, not `EventSource`) |
|
|
57
|
+
| File upload + progress | `api.upload()` + `onUploadProgress` |
|
|
58
|
+
| Bundle size | ~3.5KB gzip (HTTP core) |
|
|
17
59
|
|
|
18
|
-
|
|
60
|
+
Search terms this package targets: *fetch client for tanstack query*, *react query http client*, *next.js ssr fetch cookies*, *axios alternative typescript*, *openapi fetch codegen*.
|
|
19
61
|
|
|
20
62
|
---
|
|
21
63
|
|
|
@@ -921,6 +963,7 @@ npm run example
|
|
|
921
963
|
```ts
|
|
922
964
|
import {
|
|
923
965
|
createFetch,
|
|
966
|
+
createFormData,
|
|
924
967
|
createFetchError,
|
|
925
968
|
isFetchError,
|
|
926
969
|
isAbortError,
|
|
@@ -936,10 +979,26 @@ import {
|
|
|
936
979
|
| Method | Description |
|
|
937
980
|
| --- | --- |
|
|
938
981
|
| `get/post/put/patch/delete` | Typed HTTP → `Promise<T>` |
|
|
982
|
+
| `upload(path, opts?)` | Multipart / file upload → `Promise<T>` |
|
|
939
983
|
| `request(method, path, opts?)` | Generic verb |
|
|
940
984
|
| `sse(path, { onMessage })` | Simple stream — returns `{ close }` |
|
|
941
985
|
| `sse(path)` | Advanced — `for await` iterable |
|
|
942
986
|
| `use` / `eject` | Interceptors |
|
|
987
|
+
| `createFormData(fields)` | Build `FormData` from a plain object |
|
|
988
|
+
|
|
989
|
+
## FAQ
|
|
990
|
+
|
|
991
|
+
**Is tanstack-fetch an official TanStack package?**
|
|
992
|
+
No. It is an independent MIT library shaped for `@tanstack/react-query`.
|
|
993
|
+
|
|
994
|
+
**Can I use it without React Query?**
|
|
995
|
+
Yes. It is a plain TypeScript `fetch` client; React Query is optional.
|
|
996
|
+
|
|
997
|
+
**Does it work with Next.js App Router SSR?**
|
|
998
|
+
Yes. Use `source: 'ssr'`, the `ssr-forward` plugin, and `incoming` cookies/headers.
|
|
999
|
+
|
|
1000
|
+
**How do I upload files?**
|
|
1001
|
+
Use `api.upload({ file, fields, onUploadProgress })` or `api.post` with `createFormData(...)`.
|
|
943
1002
|
|
|
944
1003
|
## License
|
|
945
1004
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tanstack-fetch",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "TypeScript fetch / HTTP client for TanStack Query & React Query. Next.js SSR, interceptors, SSE, file upload, OpenAPI — lightweight axios alternative (~3.5KB).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Mohammad Garmabi",
|
|
@@ -18,17 +18,41 @@
|
|
|
18
18
|
"homepage": "https://github.com/mohamadgarmabi/tanstack-fetch#readme",
|
|
19
19
|
"keywords": [
|
|
20
20
|
"fetch",
|
|
21
|
+
"http-client",
|
|
21
22
|
"http",
|
|
23
|
+
"api-client",
|
|
24
|
+
"rest-client",
|
|
22
25
|
"typescript",
|
|
23
26
|
"tanstack",
|
|
24
27
|
"tanstack-query",
|
|
28
|
+
"tanstack-react-query",
|
|
25
29
|
"react-query",
|
|
30
|
+
"@tanstack/react-query",
|
|
31
|
+
"queryfn",
|
|
32
|
+
"react",
|
|
33
|
+
"nextjs",
|
|
34
|
+
"next.js",
|
|
26
35
|
"ssr",
|
|
36
|
+
"server-side-rendering",
|
|
37
|
+
"edge",
|
|
27
38
|
"sse",
|
|
39
|
+
"server-sent-events",
|
|
40
|
+
"streaming",
|
|
28
41
|
"openapi",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"interceptor"
|
|
42
|
+
"openapi-codegen",
|
|
43
|
+
"codegen",
|
|
44
|
+
"interceptor",
|
|
45
|
+
"middleware",
|
|
46
|
+
"axios-alternative",
|
|
47
|
+
"axios",
|
|
48
|
+
"ky",
|
|
49
|
+
"ofetch",
|
|
50
|
+
"multipart",
|
|
51
|
+
"formdata",
|
|
52
|
+
"file-upload",
|
|
53
|
+
"upload-progress",
|
|
54
|
+
"abortsignal",
|
|
55
|
+
"fetch-wrapper"
|
|
32
56
|
],
|
|
33
57
|
"type": "module",
|
|
34
58
|
"sideEffects": false,
|