-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaxios.ts
55 lines (49 loc) · 1.21 KB
/
axios.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const templateAxios = `import axios from "axios";
import { AxiosRequestConfig } from "axios";
export type FetchResult<T> = T;
export const get = <T>(
url: string,
params: Record<string, any>,
options?: Omit<AxiosRequestConfig, "params">
) =>
axios
.get<T>(url, { ...options, params })
.then((response) => response.data)
.catch((error) => {
console.error(error);
});
export const post = <T>(
url: string,
data: Record<string, any> | FormData,
options?: Omit<AxiosRequestConfig, "data">
) =>
axios
.post<T>(url, { ...options, data })
.then((response) => response.data)
.catch((error) => {
console.error(error);
});
export const put = <T>(
url: string,
data: Record<string, any>,
options?: Omit<AxiosRequestConfig, "data">
) =>
axios
.put<T>(url, { ...options, data })
.then((response) => response.data)
.catch((error) => {
console.error(error);
});
export const del = <T>(
url: string,
data: Record<string, any>,
options?: Omit<AxiosRequestConfig, "data">
) =>
axios
.delete<T>(url, { ...options, data })
.then((response) => response.data)
.catch((error) => {
console.error(error);
});
`;
export default templateAxios;