@hyper-fetch/axios 10.0.0 โ†’ 10.1.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.
Files changed (2) hide show
  1. package/README.md +98 -45
  2. package/package.json +7 -4
package/README.md CHANGED
@@ -1,45 +1,40 @@
1
- # ๐Ÿ›๏ธ Hyper Fetch Axios
1
+ <p align="center">
2
+ <a href="https://hyperfetch.bettertyped.com/docs/integrations/adapter-axios/overview"><img src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/.github/assets/packages/axios.png" alt="Hyper Fetch Axios. Axios underneath. HyperFetch on top. Keep your interceptors and Axios options, add typed requests, cache, retries and React hooks." /></a>
3
+ </p>
2
4
 
3
5
  <p align="center">
4
- <b>Use Axios as the HTTP engine for HyperFetch. Drop-in replacement with interceptors and all Axios features.</b>
6
+ <a href="https://hyperfetch.bettertyped.com/docs/integrations/adapter-axios/overview"><b>Quick Start</b></a> ยท
7
+ <a href="https://hyperfetch.bettertyped.com/docs/integrations/adapter-axios/overview">Documentation</a> ยท
8
+ <a href="https://hyperfetch.bettertyped.com/docs/api/adapter-axios/Variables/AxiosAdapter">API Reference</a> ยท
9
+ <a href="https://github.com/BetterTyped/hyper-fetch">GitHub</a> ยท
10
+ <a href="https://discord.gg/7upC2kVmyM">Discord</a>
5
11
  </p>
6
12
 
7
13
  <p align="center">
8
- <a href="https://bettertyped.com/">
9
- <img src="https://custom-icon-badges.demolab.com/static/v1?label=&message=BetterTyped&color=333&logo=BT" />
10
- </a>
11
- <a href="https://github.com/BetterTyped/hyper-fetch">
12
- <img src="https://custom-icon-badges.demolab.com/github/stars/BetterTyped/hyper-fetch?logo=star&color=118ab2" />
13
- </a>
14
- <a href="https://github.com/BetterTyped/hyper-fetch/blob/main/License.md">
15
- <img src="https://custom-icon-badges.demolab.com/github/license/BetterTyped/hyper-fetch?logo=law&color=yellow" />
16
- </a>
17
- <a href="https://www.npmjs.com/package/@hyper-fetch/axios">
18
- <img src="https://custom-icon-badges.demolab.com/npm/v/@hyper-fetch/axios.svg?logo=npm&color=e76f51" />
19
- </a>
20
- <a href="https://www.npmjs.com/package/@hyper-fetch/axios">
21
- <img src="https://custom-icon-badges.demolab.com/npm/dm/@hyper-fetch/axios?logoColor=fff&logo=trending-up" />
22
- </a>
23
- <a href="https://github.com/BetterTyped/hyper-fetch">
24
- <img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
25
- </a>
26
- <a href="https://bundlephobia.com/package/@hyper-fetch/axios">
27
- <img src="https://custom-icon-badges.demolab.com/bundlephobia/minzip/@hyper-fetch/axios?color=64BC4B&logo=package" />
28
- </a>
14
+ <a href="https://github.com/BetterTyped/hyper-fetch"><img src="https://img.shields.io/github/stars/BetterTyped/hyper-fetch?style=flat&logo=github&color=333" alt="GitHub stars" /></a>
15
+ <a href="https://www.npmjs.com/package/@hyper-fetch/axios"><img src="https://img.shields.io/npm/v/@hyper-fetch/axios?logo=npm&color=e76f51" alt="npm version" /></a>
16
+ <a href="https://www.npmjs.com/package/@hyper-fetch/axios"><img src="https://api.maciejpyrc.com/portfolio/npm/downloads.svg?packages=@hyper-fetch/axios&color=fbc646" alt="Monthly downloads" /></a>
17
+ <a href="https://bundlejs.com/?q=@hyper-fetch/axios"><img src="https://api.maciejpyrc.com/portfolio/npm/size.svg?package=@hyper-fetch/axios&external=@hyper-fetch/core,axios" alt="Bundle size" /></a>
18
+ <a href="https://github.com/BetterTyped/hyper-fetch"><img src="https://img.shields.io/badge/TypeScript-strict-3178C6?logo=typescript&logoColor=white" alt="TypeScript" /></a>
19
+ <a href="https://hyperfetch.bettertyped.com/docs/integrations/adapter-axios/overview"><img src="https://img.shields.io/badge/Axios-adapter-5A29E4?logo=axios&logoColor=white" alt="Axios" /></a>
20
+ <a href="https://github.com/BetterTyped/hyper-fetch/blob/main/License.md"><img src="https://img.shields.io/github/license/BetterTyped/hyper-fetch?color=blue" alt="License" /></a>
29
21
  </p>
30
22
 
31
23
  ## ๐Ÿ“– About
32
24
 
33
- This adapter replaces HyperFetch's built-in HTTP engine with Axios. You get all of Axios's features โ€” interceptors,
34
- automatic JSON transforms, request/response transforms โ€” while keeping HyperFetch's typed request system, caching,
35
- queuing, and React hooks.
25
+ `@hyper-fetch/axios` swaps the default HTTP transport of Hyper Fetch for Axios. Your interceptors, `axios.defaults`
26
+ and Axios request options keep working, and every request gains typed params and responses, cache, retries, offline
27
+ replay and React hooks. Your requests do not change, only the engine that sends them.
36
28
 
37
29
  ## ๐ŸŽฏ Key Capabilities
38
30
 
39
- - ๐Ÿ”Œ **One line to switch** โ€” Replace the default HTTP engine with Axios without touching your requests
40
- - ๐ŸŽฏ **Keep your interceptors** โ€” Interceptors and defaults registered on the default `axios` export apply to every request
41
- - โœจ **All HyperFetch features stay** โ€” Caching, queuing, types, offline support, React hooks โ€” nothing lost
42
- - ๐Ÿ”ง **Axios options per request** โ€” Pass `timeout`, `responseType`, `withCredentials` and other Axios config through `options`
31
+ - ๐Ÿ”Œ **One line to switch** - `setAdapter(AxiosAdapter)` and every existing request goes through Axios
32
+ - ๐ŸŽฏ **Keep your interceptors** - Interceptors and defaults on the default `axios` export apply to every request
33
+ - ๐Ÿ”ง **Axios options per request** - `timeout`, `responseType`, `withCredentials`, `proxy` and agents through `options`
34
+ - ๐Ÿ“ˆ **Every progress event** - Axios reports incremental upload progress in the browser, not one final event
35
+ - ๐Ÿ–ฅ๏ธ **Node-only options** - `proxy`, `httpAgent`, `httpsAgent` and `maxRedirects` on the server
36
+ - ๐Ÿงพ **Response headers in `extra`** - Read the Axios response headers next to typed `data`
37
+ - โœจ **Nothing else changes** - Cache, retries, deduplication, offline replay and React hooks work as before
43
38
 
44
39
  ## ๐Ÿš€ Quick Start
45
40
 
@@ -51,26 +46,33 @@ npm install @hyper-fetch/core @hyper-fetch/axios axios
51
46
  import { createClient } from "@hyper-fetch/core";
52
47
  import { AxiosAdapter } from "@hyper-fetch/axios";
53
48
 
49
+ // AxiosAdapter is a ready instance, pass it without parentheses
54
50
  const client = createClient({ url: "https://api.example.com" }).setAdapter(AxiosAdapter);
51
+
52
+ const getUser = client.createRequest<{ response: User }>()({
53
+ endpoint: "/users/:userId",
54
+ options: { timeout: 5000, withCredentials: true }, // Axios options, typed
55
+ });
56
+
57
+ const { data, error, extra } = await getUser.setParams({ userId: 1 }).send();
58
+ // extra.headers holds the Axios response headers
55
59
  ```
56
60
 
57
61
  ## ๐Ÿ“š Documentation
58
62
 
59
- - [Axios Adapter Docs](https://hyperfetch.bettertyped.com/docs/integrations/adapter-axios)
60
- - [Getting Started](https://hyperfetch.bettertyped.com/docs/getting-started/quick-start)
61
- - [API Reference](https://hyperfetch.bettertyped.com/api/)
63
+ - **[Axios Adapter](https://hyperfetch.bettertyped.com/docs/integrations/adapter-axios/overview)** - Setup, options, progress and errors
64
+ - **[Getting Started](https://hyperfetch.bettertyped.com/docs/getting-started/quick-start)** - The core request API
65
+ - **[API Reference](https://hyperfetch.bettertyped.com/docs/api/adapter-axios/Variables/AxiosAdapter)** - `AxiosAdapter` and its types
62
66
 
63
67
  ## ๐Ÿ’ก Examples
64
68
 
65
- ### Use with Axios interceptors
69
+ ### Keep your Axios interceptors
66
70
 
67
- `AxiosAdapter` is a ready-made adapter instance, not a factory, and it sends every request through the default `axios`
68
- export. Register interceptors on that export. Custom instances from `axios.create()` are not used by the adapter.
71
+ `AxiosAdapter` sends every request through the default `axios` export, so register interceptors there. Instances from
72
+ `axios.create()` are not used by the adapter.
69
73
 
70
74
  ```ts
71
75
  import axios from "axios";
72
- import { createClient } from "@hyper-fetch/core";
73
- import { AxiosAdapter } from "@hyper-fetch/axios";
74
76
 
75
77
  axios.interceptors.request.use((config) => {
76
78
  config.headers.Authorization = `Bearer ${getToken()}`;
@@ -88,25 +90,76 @@ axios.interceptors.response.use(
88
90
  const client = createClient({ url: "https://api.example.com" }).setAdapter(AxiosAdapter);
89
91
  ```
90
92
 
91
- ### Set Axios defaults for every request
93
+ ### A timeout and GET deduplication for every request
92
94
 
93
95
  ```ts
96
+ // Axios has no default timeout and no GET deduplication, so set both once
94
97
  const client = createClient({ url: "https://api.example.com" }).setAdapter(
95
- AxiosAdapter.setAdapterDefaults(() => ({ timeout: 5000 })),
98
+ AxiosAdapter.setAdapterDefaults(() => ({ timeout: 5000 })).setRequestDefaults((options) =>
99
+ (options.method ?? "GET") === "GET" ? { deduplicate: true } : {},
100
+ ),
96
101
  );
97
102
  ```
98
103
 
99
- ### Create typed requests (same as core)
104
+ ### Download a file
100
105
 
101
106
  ```ts
102
- const getUsers = client.createRequest<{ response: User[] }>()({
103
- endpoint: "/users",
104
- method: "GET",
107
+ const downloadReport = client.createRequest<{ response: Blob }>()({
108
+ endpoint: "/reports/:reportId",
109
+ options: { responseType: "blob", timeout: 30000 },
105
110
  });
106
111
 
107
- const { data, error } = await getUsers.send();
112
+ const { data: report } = await downloadReport.setParams({ reportId: 42 }).send();
108
113
  ```
109
114
 
115
+ ### Upload with progress
116
+
117
+ ```ts
118
+ const uploadAvatar = client.createRequest<{ response: { url: string }; payload: FormData }>()({
119
+ endpoint: "/avatar",
120
+ method: "POST",
121
+ });
122
+
123
+ const form = new FormData();
124
+ form.append("file", file);
125
+
126
+ await uploadAvatar.send({
127
+ payload: form,
128
+ onUploadProgress: ({ progress, loaded, total }) => setUpload({ progress, loaded, total }),
129
+ });
130
+ ```
131
+
132
+ ## ๐Ÿงฉ Hyper Fetch Ecosystem
133
+
134
+ One typed client for every backend. Swap the adapter and keep the same `createRequest()` everywhere.
135
+
136
+ <table align="center">
137
+ <tr>
138
+ <td align="center" width="110"><a href="https://github.com/BetterTyped/hyper-fetch/tree/main/packages/core"><img src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/documentation/static/img/integration-hyper-fetch.svg" width="36" height="36" alt="" /><br /><sub><b>Core</b></sub></a></td>
139
+ <td align="center" width="110"><a href="https://github.com/BetterTyped/hyper-fetch/tree/main/packages/react"><img src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/documentation/static/img/integration-react.svg" width="36" height="36" alt="" /><br /><sub><b>React</b></sub></a></td>
140
+ <td align="center" width="110"><a href="https://github.com/BetterTyped/hyper-fetch/tree/main/packages/sockets"><img src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/documentation/static/img/integration-sockets.svg" width="36" height="36" alt="" /><br /><sub><b>Sockets</b></sub></a></td>
141
+ <td align="center" width="110"><a href="https://github.com/BetterTyped/hyper-fetch/tree/main/packages/cli"><img src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/documentation/static/img/integration-openapi.svg" width="36" height="36" alt="" /><br /><sub><b>OpenAPI CLI</b></sub></a></td>
142
+ <td align="center" width="110"><a href="https://github.com/BetterTyped/hyper-fetch/tree/main/packages/adapter-graphql"><img src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/documentation/static/img/integration-graphql.svg" width="36" height="36" alt="" /><br /><sub><b>GraphQL</b></sub></a></td>
143
+ <td align="center" width="110"><a href="https://github.com/BetterTyped/hyper-fetch/tree/main/packages/adapter-trpc"><img src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/documentation/static/img/integration-trpc.svg" width="36" height="36" alt="" /><br /><sub><b>tRPC</b></sub></a></td>
144
+ </tr>
145
+ <tr>
146
+ <td align="center" width="110"><a href="https://github.com/BetterTyped/hyper-fetch/tree/main/packages/adapter-orpc"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/documentation/static/img/integration-orpc-dark.svg" /><img src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/documentation/static/img/integration-orpc.svg" width="36" height="36" alt="" /></picture><br /><sub><b>oRPC</b></sub></a></td>
147
+ <td align="center" width="110"><a href="https://github.com/BetterTyped/hyper-fetch/tree/main/packages/hono"><img src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/documentation/static/img/integration-hono.svg" width="36" height="36" alt="" /><br /><sub><b>Hono</b></sub></a></td>
148
+ <td align="center" width="110"><a href="https://github.com/BetterTyped/hyper-fetch/tree/main/packages/elysia"><img src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/documentation/static/img/integration-elysia.svg" width="36" height="36" alt="" /><br /><sub><b>Elysia</b></sub></a></td>
149
+ <td align="center" width="110"><a href="https://github.com/BetterTyped/hyper-fetch/tree/main/packages/adapter-firebase"><img src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/documentation/static/img/integration-firebase.svg" width="36" height="36" alt="" /><br /><sub><b>Firebase</b></sub></a></td>
150
+ <td align="center" width="110"><a href="https://github.com/BetterTyped/hyper-fetch/tree/main/packages/adapter-axios"><img src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/documentation/static/img/integration-axios.svg" width="36" height="36" alt="" /><br /><sub><b>Axios</b></sub></a></td>
151
+ <td align="center" width="110"><a href="https://github.com/BetterTyped/hyper-fetch/tree/main/packages/hyper-flow"><img src="https://raw.githubusercontent.com/BetterTyped/hyper-fetch/main/documentation/static/img/hyper-flow.svg" width="36" height="36" alt="" /><br /><sub><b>HyperFlow</b></sub></a></td>
152
+ </tr>
153
+ </table>
154
+
155
+ ## ๐Ÿ’– Sponsors
156
+
157
+ <p align="center">
158
+ <a href="https://github.com/sponsors/prc5">
159
+ <img src="https://raw.githubusercontent.com/prc5/sponsors/main/packages/other/sponsorkit/sponsors.svg?raw=true" alt="Sponsors" />
160
+ </a>
161
+ </p>
162
+
110
163
  ## License
111
164
 
112
165
  [Apache-2.0](https://github.com/BetterTyped/hyper-fetch/blob/main/License.md)
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@hyper-fetch/axios",
3
- "version": "10.0.0",
4
- "description": "Simple axios adapter for Hyper Fetch",
3
+ "version": "10.1.1",
4
+ "description": "Axios adapter for HyperFetch: send typed requests through Axios with HyperFetch caching, retries and upload progress",
5
5
  "author": "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
6
- "homepage": "https://hyperfetch.bettertyped.com/",
6
+ "homepage": "https://hyperfetch.bettertyped.com/docs/integrations/adapter-axios/overview/",
7
7
  "license": "Apache-2.0",
8
8
  "main": "dist/index.mjs",
9
9
  "module": "dist/index.mjs",
@@ -45,6 +45,9 @@
45
45
  "keywords": [
46
46
  "axios",
47
47
  "adapter",
48
- "hyper fetch"
48
+ "http-client",
49
+ "upload-progress",
50
+ "typescript",
51
+ "hyperfetch"
49
52
  ]
50
53
  }