@hyper-fetch/axios 9.8.0 → 9.9.0
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 +18 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,9 +37,9 @@ queuing, and React hooks.
|
|
|
37
37
|
## 🎯 Key Capabilities
|
|
38
38
|
|
|
39
39
|
- 🔌 **One line to switch** — Replace the default HTTP engine with Axios without touching your requests
|
|
40
|
-
- 🎯 **Keep your interceptors** —
|
|
40
|
+
- 🎯 **Keep your interceptors** — Interceptors and defaults registered on the default `axios` export apply to every request
|
|
41
41
|
- ✨ **All HyperFetch features stay** — Caching, queuing, types, offline support, React hooks — nothing lost
|
|
42
|
-
- 🔧 **
|
|
42
|
+
- 🔧 **Axios options per request** — Pass `timeout`, `responseType`, `withCredentials` and other Axios config through `options`
|
|
43
43
|
|
|
44
44
|
## 🚀 Quick Start
|
|
45
45
|
|
|
@@ -51,7 +51,7 @@ npm install @hyper-fetch/core @hyper-fetch/axios axios
|
|
|
51
51
|
import { createClient } from "@hyper-fetch/core";
|
|
52
52
|
import { AxiosAdapter } from "@hyper-fetch/axios";
|
|
53
53
|
|
|
54
|
-
const client = createClient({ url: "https://api.example.com" }).setAdapter(AxiosAdapter
|
|
54
|
+
const client = createClient({ url: "https://api.example.com" }).setAdapter(AxiosAdapter);
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
## 📚 Documentation
|
|
@@ -64,19 +64,20 @@ const client = createClient({ url: "https://api.example.com" }).setAdapter(Axios
|
|
|
64
64
|
|
|
65
65
|
### Use with Axios interceptors
|
|
66
66
|
|
|
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.
|
|
69
|
+
|
|
67
70
|
```ts
|
|
68
71
|
import axios from "axios";
|
|
69
72
|
import { createClient } from "@hyper-fetch/core";
|
|
70
73
|
import { AxiosAdapter } from "@hyper-fetch/axios";
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
axiosInstance.interceptors.request.use((config) => {
|
|
75
|
+
axios.interceptors.request.use((config) => {
|
|
75
76
|
config.headers.Authorization = `Bearer ${getToken()}`;
|
|
76
77
|
return config;
|
|
77
78
|
});
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
axios.interceptors.response.use(
|
|
80
81
|
(response) => response,
|
|
81
82
|
(error) => {
|
|
82
83
|
if (error.response?.status === 401) refreshToken();
|
|
@@ -84,7 +85,15 @@ axiosInstance.interceptors.response.use(
|
|
|
84
85
|
},
|
|
85
86
|
);
|
|
86
87
|
|
|
87
|
-
const client = createClient({ url: "https://api.example.com" }).setAdapter(AxiosAdapter
|
|
88
|
+
const client = createClient({ url: "https://api.example.com" }).setAdapter(AxiosAdapter);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Set Axios defaults for every request
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const client = createClient({ url: "https://api.example.com" }).setAdapter(
|
|
95
|
+
AxiosAdapter.setAdapterDefaults(() => ({ timeout: 5000 })),
|
|
96
|
+
);
|
|
88
97
|
```
|
|
89
98
|
|
|
90
99
|
### Create typed requests (same as core)
|
|
@@ -100,4 +109,4 @@ const { data, error } = await getUsers.send();
|
|
|
100
109
|
|
|
101
110
|
## License
|
|
102
111
|
|
|
103
|
-
[
|
|
112
|
+
[Apache-2.0](https://github.com/BetterTyped/hyper-fetch/blob/main/License.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyper-fetch/axios",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.9.0",
|
|
4
4
|
"description": "Simple axios adapter for Hyper Fetch",
|
|
5
5
|
"author": "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
|
|
6
6
|
"homepage": "https://hyperfetch.bettertyped.com/",
|