@hyper-fetch/axios 9.8.1 → 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.
Files changed (2) hide show
  1. package/README.md +17 -8
  2. 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** — Use existing Axios request/response interceptors and error transforms
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
- - 🔧 **Bring your own instance** — Pass a pre-configured Axios instance with custom defaults and auth headers
42
+ - 🔧 **Axios options per request** — Pass `timeout`, `responseType`, `withCredentials` and other Axios config through `options`
43
43
 
44
44
  ## 🚀 Quick Start
45
45
 
@@ -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
- const axiosInstance = axios.create({ baseURL: "https://api.example.com" });
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
- axiosInstance.interceptors.response.use(
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({ instance: axiosInstance }));
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
- [MIT](https://github.com/BetterTyped/hyper-fetch/blob/main/License.md)
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.8.1",
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/",