@hyper-fetch/axios 8.1.0 โ 8.2.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 +64 -30
- package/dist/adapter/adapter.d.ts +1 -0
- package/dist/adapter/adapter.d.ts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/adapter/adapter.ts +1 -0
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# ๐๏ธ Hyper Fetch Axios
|
|
2
2
|
|
|
3
|
-
<p>
|
|
3
|
+
<p align="center">
|
|
4
|
+
<b>Use Axios as the HTTP engine for HyperFetch. Drop-in replacement with interceptors and all Axios features.</b>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
4
8
|
<a href="https://bettertyped.com/">
|
|
5
9
|
<img src="https://custom-icon-badges.demolab.com/static/v1?label=&message=BetterTyped&color=333&logo=BT" />
|
|
6
10
|
</a>
|
|
@@ -13,57 +17,87 @@
|
|
|
13
17
|
<a href="https://www.npmjs.com/package/@hyper-fetch/axios">
|
|
14
18
|
<img src="https://custom-icon-badges.demolab.com/npm/v/@hyper-fetch/axios.svg?logo=npm&color=e76f51" />
|
|
15
19
|
</a>
|
|
16
|
-
<a href="https://
|
|
17
|
-
<img src="https://custom-icon-badges.demolab.com/
|
|
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" />
|
|
18
22
|
</a>
|
|
19
23
|
<a href="https://github.com/BetterTyped/hyper-fetch">
|
|
20
|
-
<img src="https://custom-icon-badges.demolab.com/badge
|
|
24
|
+
<img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
|
|
21
25
|
</a>
|
|
22
|
-
<a href="https://
|
|
26
|
+
<a href="https://bundlephobia.com/package/@hyper-fetch/axios">
|
|
23
27
|
<img src="https://custom-icon-badges.demolab.com/bundlephobia/minzip/@hyper-fetch/axios?color=64BC4B&logo=package" />
|
|
24
28
|
</a>
|
|
25
29
|
</p>
|
|
26
30
|
|
|
27
|
-
## About
|
|
31
|
+
## ๐ About
|
|
32
|
+
|
|
33
|
+
This adapter replaces HyperFetch's built-in HTTP engine with Axios. You get all of Axios's features โ interceptors, automatic JSON transforms, request/response transforms โ while keeping HyperFetch's typed request system, caching, queuing, and React hooks.
|
|
34
|
+
|
|
35
|
+
## ๐ฏ Key Capabilities
|
|
36
|
+
|
|
37
|
+
- ๐ **One line to switch** โ Replace the default HTTP engine with Axios without touching your requests
|
|
38
|
+
- ๐ฏ **Keep your interceptors** โ Use existing Axios request/response interceptors and error transforms
|
|
39
|
+
- โจ **All HyperFetch features stay** โ Caching, queuing, types, offline support, React hooks โ nothing lost
|
|
40
|
+
- ๐ง **Bring your own instance** โ Pass a pre-configured Axios instance with custom defaults and auth headers
|
|
28
41
|
|
|
29
|
-
|
|
30
|
-
retrieval and manipulation of data. Benefit from the convenience and efficiency of Hyper Fetch.
|
|
42
|
+
## ๐ Quick Start
|
|
31
43
|
|
|
32
|
-
|
|
44
|
+
```bash
|
|
45
|
+
npm install @hyper-fetch/core @hyper-fetch/axios axios
|
|
46
|
+
```
|
|
33
47
|
|
|
34
|
-
|
|
48
|
+
```ts
|
|
49
|
+
import { createClient } from "@hyper-fetch/core";
|
|
50
|
+
import { AxiosAdapter } from "@hyper-fetch/axios";
|
|
35
51
|
|
|
36
|
-
|
|
52
|
+
const client = createClient({ url: "https://api.example.com" }).setAdapter(AxiosAdapter());
|
|
53
|
+
```
|
|
37
54
|
|
|
38
|
-
|
|
39
|
-
[Read more](https://hyperfetch.bettertyped.com/docs/guides/react/core/window-focus-blur)
|
|
55
|
+
## ๐ Documentation
|
|
40
56
|
|
|
41
|
-
|
|
57
|
+
- [Axios Adapter Docs](https://hyperfetch.bettertyped.com/docs/integrations/adapter-axios)
|
|
58
|
+
- [Getting Started](https://hyperfetch.bettertyped.com/docs/getting-started/quick-start)
|
|
59
|
+
- [API Reference](https://hyperfetch.bettertyped.com/api/)
|
|
42
60
|
|
|
43
|
-
|
|
61
|
+
## ๐ก Examples
|
|
44
62
|
|
|
45
|
-
|
|
63
|
+
### Use with Axios interceptors
|
|
46
64
|
|
|
47
|
-
|
|
65
|
+
```ts
|
|
66
|
+
import axios from "axios";
|
|
67
|
+
import { createClient } from "@hyper-fetch/core";
|
|
68
|
+
import { AxiosAdapter } from "@hyper-fetch/axios";
|
|
48
69
|
|
|
49
|
-
|
|
70
|
+
const axiosInstance = axios.create({ baseURL: "https://api.example.com" });
|
|
50
71
|
|
|
51
|
-
|
|
72
|
+
axiosInstance.interceptors.request.use((config) => {
|
|
73
|
+
config.headers.Authorization = `Bearer ${getToken()}`;
|
|
74
|
+
return config;
|
|
75
|
+
});
|
|
52
76
|
|
|
53
|
-
|
|
77
|
+
axiosInstance.interceptors.response.use(
|
|
78
|
+
(response) => response,
|
|
79
|
+
(error) => {
|
|
80
|
+
if (error.response?.status === 401) refreshToken();
|
|
81
|
+
return Promise.reject(error);
|
|
82
|
+
},
|
|
83
|
+
);
|
|
54
84
|
|
|
55
|
-
|
|
85
|
+
const client = createClient({ url: "https://api.example.com" }).setAdapter(
|
|
86
|
+
AxiosAdapter({ instance: axiosInstance }),
|
|
87
|
+
);
|
|
88
|
+
```
|
|
56
89
|
|
|
57
|
-
|
|
90
|
+
### Create typed requests (same as core)
|
|
58
91
|
|
|
59
|
-
|
|
92
|
+
```ts
|
|
93
|
+
const getUsers = client.createRequest<{ response: User[] }>()({
|
|
94
|
+
endpoint: "/users",
|
|
95
|
+
method: "GET",
|
|
96
|
+
});
|
|
60
97
|
|
|
61
|
-
|
|
98
|
+
const { data, error } = await getUsers.send();
|
|
99
|
+
```
|
|
62
100
|
|
|
63
|
-
##
|
|
101
|
+
## License
|
|
64
102
|
|
|
65
|
-
|
|
66
|
-
- #### [Docs](https://hyperfetch.bettertyped.com/)
|
|
67
|
-
- #### [API](https://hyperfetch.bettertyped.com/api/)
|
|
68
|
-
- #### [NPM](https://www.npmjs.com/package/@hyper-fetch/axios)
|
|
69
|
-
- #### [Guides](https://hyperfetch.bettertyped.com/guides/Basic/Setup)
|
|
103
|
+
[MIT](https://github.com/BetterTyped/hyper-fetch/blob/main/License.md)
|
|
@@ -2,5 +2,6 @@ import { Adapter } from '@hyper-fetch/core';
|
|
|
2
2
|
import { Method as AxiosMethods, AxiosRequestConfig } from 'axios';
|
|
3
3
|
import { AxiosExtra } from './adapter.types';
|
|
4
4
|
export type AxiosAdapterType = typeof AxiosAdapter;
|
|
5
|
+
/** Pre-configured adapter that uses Axios as the underlying HTTP transport. Supports upload/download progress and abort. */
|
|
5
6
|
export declare const AxiosAdapter: Adapter<Omit<AxiosRequestConfig<any>, "url" | "baseURL" | "method" | "onUploadProgress" | "onDownloadProgress" | "data">, AxiosMethods, number, AxiosExtra, string | import('@hyper-fetch/core').QueryParamsType | import('@hyper-fetch/core').EmptyTypes, undefined, string, import('@hyper-fetch/core').DefaultMapperType, (queryParams: import('@hyper-fetch/core').QueryParamsType | string | import('@hyper-fetch/core').EmptyTypes, options?: import('@hyper-fetch/core').QueryStringifyOptionsType) => string, import('@hyper-fetch/core').DefaultMapperType, import('@hyper-fetch/core').DefaultMapperType>;
|
|
6
7
|
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAwB,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAGxE,OAAO,KAAK,EAAE,UAAU,EAAmB,MAAM,iBAAiB,CAAC;AAEnE,MAAM,MAAM,gBAAgB,GAAG,OAAO,YAAY,CAAC;AAEnD,eAAO,MAAM,YAAY,qlBAgFtB,CAAC"}
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAwB,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAGxE,OAAO,KAAK,EAAE,UAAU,EAAmB,MAAM,iBAAiB,CAAC;AAEnE,MAAM,MAAM,gBAAgB,GAAG,OAAO,YAAY,CAAC;AAEnD,4HAA4H;AAC5H,eAAO,MAAM,YAAY,qlBAgFtB,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Adapter, stringifyQueryParams } from "@hyper-fetch/core";
|
|
2
2
|
import axios, { AxiosHeaders } from "axios";
|
|
3
3
|
//#region src/adapter/adapter.ts
|
|
4
|
+
/** Pre-configured adapter that uses Axios as the underlying HTTP transport. Supports upload/download progress and abort. */
|
|
4
5
|
var AxiosAdapter = new Adapter({
|
|
5
6
|
name: "axios-adapter",
|
|
6
7
|
defaultMethod: "GET",
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/adapter/adapter.ts"],"sourcesContent":["import { Adapter, stringifyQueryParams } from \"@hyper-fetch/core\";\nimport type { Method as AxiosMethods, AxiosRequestConfig } from \"axios\";\nimport axios, { AxiosHeaders } from \"axios\";\n\nimport type { AxiosExtra, RawAxiosHeaders } from \"./adapter.types\";\n\nexport type AxiosAdapterType = typeof AxiosAdapter;\n\nexport const AxiosAdapter = new Adapter<\n Omit<AxiosRequestConfig, \"url\" | \"baseURL\" | \"method\" | \"onUploadProgress\" | \"onDownloadProgress\" | \"data\">,\n AxiosMethods,\n number,\n AxiosExtra\n>({\n name: \"axios-adapter\",\n defaultMethod: \"GET\",\n defaultExtra: { headers: {} },\n systemErrorStatus: 0,\n systemErrorExtra: { headers: {} },\n})\n .setQueryParamsMapper(stringifyQueryParams)\n .setFetcher(\n async ({\n url,\n endpoint,\n queryParams,\n request,\n headers,\n payload,\n adapter,\n adapterOptions,\n onError,\n onResponseEnd,\n onRequestEnd,\n createAbortListener,\n onResponseProgress,\n onRequestProgress,\n onResponseStart,\n onBeforeRequest,\n onRequestStart,\n onSuccess,\n getAbortController,\n }) => {\n const { method } = request;\n\n const fullUrl = `${url}${endpoint}${queryParams}`;\n\n onBeforeRequest();\n\n const controller = getAbortController();\n const unmountListener = () =>\n createAbortListener({\n status: 0,\n extra: { headers: {} },\n });\n\n onRequestStart();\n axios({\n ...adapterOptions,\n data: payload,\n method,\n url: fullUrl,\n signal: controller?.signal,\n headers: new AxiosHeaders(headers as RawAxiosHeaders),\n onUploadProgress: (progressEvent) => {\n onRequestProgress(progressEvent);\n },\n onDownloadProgress: (progressEvent) => {\n onRequestEnd();\n onResponseStart();\n onResponseProgress(progressEvent);\n },\n })\n .then((response) => {\n onSuccess({ data: response.data, status: response.status, extra: { headers: response.headers } });\n onResponseEnd();\n })\n .catch((error) => {\n onError({\n error,\n status: error.response?.status || adapter.systemErrorStatus,\n extra: { headers: error.response?.headers },\n });\n })\n .finally(() => {\n unmountListener();\n });\n },\n );\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/adapter/adapter.ts"],"sourcesContent":["import { Adapter, stringifyQueryParams } from \"@hyper-fetch/core\";\nimport type { Method as AxiosMethods, AxiosRequestConfig } from \"axios\";\nimport axios, { AxiosHeaders } from \"axios\";\n\nimport type { AxiosExtra, RawAxiosHeaders } from \"./adapter.types\";\n\nexport type AxiosAdapterType = typeof AxiosAdapter;\n\n/** Pre-configured adapter that uses Axios as the underlying HTTP transport. Supports upload/download progress and abort. */\nexport const AxiosAdapter = new Adapter<\n Omit<AxiosRequestConfig, \"url\" | \"baseURL\" | \"method\" | \"onUploadProgress\" | \"onDownloadProgress\" | \"data\">,\n AxiosMethods,\n number,\n AxiosExtra\n>({\n name: \"axios-adapter\",\n defaultMethod: \"GET\",\n defaultExtra: { headers: {} },\n systemErrorStatus: 0,\n systemErrorExtra: { headers: {} },\n})\n .setQueryParamsMapper(stringifyQueryParams)\n .setFetcher(\n async ({\n url,\n endpoint,\n queryParams,\n request,\n headers,\n payload,\n adapter,\n adapterOptions,\n onError,\n onResponseEnd,\n onRequestEnd,\n createAbortListener,\n onResponseProgress,\n onRequestProgress,\n onResponseStart,\n onBeforeRequest,\n onRequestStart,\n onSuccess,\n getAbortController,\n }) => {\n const { method } = request;\n\n const fullUrl = `${url}${endpoint}${queryParams}`;\n\n onBeforeRequest();\n\n const controller = getAbortController();\n const unmountListener = () =>\n createAbortListener({\n status: 0,\n extra: { headers: {} },\n });\n\n onRequestStart();\n axios({\n ...adapterOptions,\n data: payload,\n method,\n url: fullUrl,\n signal: controller?.signal,\n headers: new AxiosHeaders(headers as RawAxiosHeaders),\n onUploadProgress: (progressEvent) => {\n onRequestProgress(progressEvent);\n },\n onDownloadProgress: (progressEvent) => {\n onRequestEnd();\n onResponseStart();\n onResponseProgress(progressEvent);\n },\n })\n .then((response) => {\n onSuccess({ data: response.data, status: response.status, extra: { headers: response.headers } });\n onResponseEnd();\n })\n .catch((error) => {\n onError({\n error,\n status: error.response?.status || adapter.systemErrorStatus,\n extra: { headers: error.response?.headers },\n });\n })\n .finally(() => {\n unmountListener();\n });\n },\n );\n"],"mappings":";;;;AASA,IAAa,eAAe,IAAI,QAK9B;CACA,MAAM;CACN,eAAe;CACf,cAAc,EAAE,SAAS,EAAE,EAAE;CAC7B,mBAAmB;CACnB,kBAAkB,EAAE,SAAS,EAAE,EAAE;CAClC,CAAC,CACC,qBAAqB,qBAAqB,CAC1C,WACC,OAAO,EACL,KACA,UACA,aACA,SACA,SACA,SACA,SACA,gBACA,SACA,eACA,cACA,qBACA,oBACA,mBACA,iBACA,iBACA,gBACA,WACA,yBACI;CACJ,MAAM,EAAE,WAAW;CAEnB,MAAM,UAAU,GAAG,MAAM,WAAW;AAEpC,kBAAiB;CAEjB,MAAM,aAAa,oBAAoB;CACvC,MAAM,wBACJ,oBAAoB;EAClB,QAAQ;EACR,OAAO,EAAE,SAAS,EAAE,EAAE;EACvB,CAAC;AAEJ,iBAAgB;AAChB,OAAM;EACJ,GAAG;EACH,MAAM;EACN;EACA,KAAK;EACL,QAAQ,YAAY;EACpB,SAAS,IAAI,aAAa,QAA2B;EACrD,mBAAmB,kBAAkB;AACnC,qBAAkB,cAAc;;EAElC,qBAAqB,kBAAkB;AACrC,iBAAc;AACd,oBAAiB;AACjB,sBAAmB,cAAc;;EAEpC,CAAC,CACC,MAAM,aAAa;AAClB,YAAU;GAAE,MAAM,SAAS;GAAM,QAAQ,SAAS;GAAQ,OAAO,EAAE,SAAS,SAAS,SAAS;GAAE,CAAC;AACjG,iBAAe;GACf,CACD,OAAO,UAAU;AAChB,UAAQ;GACN;GACA,QAAQ,MAAM,UAAU,UAAU,QAAQ;GAC1C,OAAO,EAAE,SAAS,MAAM,UAAU,SAAS;GAC5C,CAAC;GACF,CACD,cAAc;AACb,mBAAiB;GACjB;EAEP"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyper-fetch/axios",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.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/",
|
package/src/adapter/adapter.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { AxiosExtra, RawAxiosHeaders } from "./adapter.types";
|
|
|
6
6
|
|
|
7
7
|
export type AxiosAdapterType = typeof AxiosAdapter;
|
|
8
8
|
|
|
9
|
+
/** Pre-configured adapter that uses Axios as the underlying HTTP transport. Supports upload/download progress and abort. */
|
|
9
10
|
export const AxiosAdapter = new Adapter<
|
|
10
11
|
Omit<AxiosRequestConfig, "url" | "baseURL" | "method" | "onUploadProgress" | "onDownloadProgress" | "data">,
|
|
11
12
|
AxiosMethods,
|