2023-05-18 11:09:31 -07:00
|
|
|
import axios, { AxiosRequestConfig } from 'axios';
|
2023-04-02 12:48:26 -07:00
|
|
|
|
|
|
|
|
async function _get<T>(url: string, options?: AxiosRequestConfig): Promise<T> {
|
2023-05-18 11:09:31 -07:00
|
|
|
const response = await axios.get(url, { ...options });
|
2023-04-02 12:48:26 -07:00
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 08:47:18 -07:00
|
|
|
async function _post(url: string, data?: any) {
|
|
|
|
|
const response = await axios.post(url, JSON.stringify(data), {
|
2023-05-18 11:09:31 -07:00
|
|
|
headers: { 'Content-Type': 'application/json' }
|
2023-04-02 12:48:26 -07:00
|
|
|
});
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-18 11:09:31 -07:00
|
|
|
async function _postMultiPart(url: string, formData: FormData, options?: AxiosRequestConfig) {
|
2023-04-02 12:48:26 -07:00
|
|
|
const response = await axios.post(url, formData, {
|
|
|
|
|
...options,
|
2023-05-18 11:09:31 -07:00
|
|
|
headers: { 'Content-Type': 'multipart/form-data' }
|
2023-04-02 12:48:26 -07:00
|
|
|
});
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function _put(url: string, data?: any) {
|
|
|
|
|
const response = await axios.put(url, JSON.stringify(data), {
|
2023-05-18 11:09:31 -07:00
|
|
|
headers: { 'Content-Type': 'application/json' }
|
2023-04-02 12:48:26 -07:00
|
|
|
});
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function _delete<T>(url: string): Promise<T> {
|
2023-04-03 12:39:00 -07:00
|
|
|
const response = await axios.delete(url);
|
2023-04-02 12:48:26 -07:00
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-18 11:09:31 -07:00
|
|
|
async function _deleteWithOptions<T>(url: string, options?: AxiosRequestConfig): Promise<T> {
|
|
|
|
|
const response = await axios.delete(url, { ...options });
|
2023-04-02 12:48:26 -07:00
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function _patch(url: string, data?: any) {
|
|
|
|
|
const response = await axios.patch(url, JSON.stringify(data), {
|
2023-05-18 11:09:31 -07:00
|
|
|
headers: { 'Content-Type': 'application/json' }
|
2023-04-02 12:48:26 -07:00
|
|
|
});
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
get: _get,
|
|
|
|
|
post: _post,
|
|
|
|
|
postMultiPart: _postMultiPart,
|
|
|
|
|
put: _put,
|
|
|
|
|
delete: _delete,
|
|
|
|
|
deleteWithOptions: _deleteWithOptions,
|
2023-05-18 11:09:31 -07:00
|
|
|
patch: _patch
|
2023-04-02 12:48:26 -07:00
|
|
|
};
|