-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.ts
33 lines (26 loc) · 968 Bytes
/
api.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
import { API_URL } from '@env';
import axios, { AxiosRequestConfig } from 'axios';
const api = axios.create({
baseURL: API_URL + '/api',
});
const get = <T extends object>(
url: string,
config: AxiosRequestConfig<any> | undefined = undefined,
): Promise<T> => api.get(url, config);
const del = <T extends object>(
url: string,
config: AxiosRequestConfig<any> | undefined = undefined,
): Promise<T> => api.delete(url, config);
const post = <T extends object>(
url: string,
data: unknown | undefined = undefined,
config: AxiosRequestConfig<any> | undefined = undefined,
): Promise<T> => api.post(url, data, config);
const put = <T extends object>(
url: string,
data: unknown | undefined = undefined,
config: AxiosRequestConfig<any> | undefined = undefined,
): Promise<T> => api.put(url, data, config);
const patch = <T extends object>(url: string, data: unknown): Promise<T> =>
api.patch(url, data);
export { get, del, post, put, patch };