|
|
@@ -1,16 +1,47 @@
|
|
|
import type { AxiosRequestConfig } from 'axios'
|
|
|
-import api from './axios'
|
|
|
+import { api } from './axios'
|
|
|
|
|
|
-export const http = {
|
|
|
- get: <T>(url: string, config?: AxiosRequestConfig) =>
|
|
|
- api.get<T>(url, config).then((res) => res.data),
|
|
|
+async function get<T>(url: string, config?: AxiosRequestConfig): Promise<T> {
|
|
|
+ const response = await api.get<T>(url, config)
|
|
|
+ return response.data
|
|
|
+}
|
|
|
+
|
|
|
+async function post<T, B = unknown>(
|
|
|
+ url: string,
|
|
|
+ body?: B,
|
|
|
+ config?: AxiosRequestConfig
|
|
|
+): Promise<T> {
|
|
|
+ const response = await api.post<T>(url, body, config)
|
|
|
+ return response.data
|
|
|
+}
|
|
|
|
|
|
- post: <T, B = unknown>(url: string, body?: B, config?: AxiosRequestConfig) =>
|
|
|
- api.post<T>(url, body, config).then((res) => res.data),
|
|
|
+async function put<T, B = unknown>(
|
|
|
+ url: string,
|
|
|
+ body?: B,
|
|
|
+ config?: AxiosRequestConfig
|
|
|
+): Promise<T> {
|
|
|
+ const response = await api.put<T>(url, body, config)
|
|
|
+ return response.data
|
|
|
+}
|
|
|
|
|
|
- put: <T, B = unknown>(url: string, body?: B, config?: AxiosRequestConfig) =>
|
|
|
- api.put<T>(url, body, config).then((res) => res.data),
|
|
|
+async function patch<T, B = unknown>(
|
|
|
+ url: string,
|
|
|
+ body?: B,
|
|
|
+ config?: AxiosRequestConfig
|
|
|
+): Promise<T> {
|
|
|
+ const response = await api.patch<T>(url, body, config)
|
|
|
+ return response.data
|
|
|
+}
|
|
|
+
|
|
|
+async function del<T>(url: string, config?: AxiosRequestConfig): Promise<T> {
|
|
|
+ const response = await api.delete<T>(url, config)
|
|
|
+ return response.data
|
|
|
+}
|
|
|
|
|
|
- delete: <T>(url: string, config?: AxiosRequestConfig) =>
|
|
|
- api.delete<T>(url, config).then((res) => res.data),
|
|
|
+export default {
|
|
|
+ get,
|
|
|
+ post,
|
|
|
+ put,
|
|
|
+ patch,
|
|
|
+ delete: del,
|
|
|
}
|