diff --git a/src/_apis/tool.ts b/src/_apis/tool.ts new file mode 100644 index 0000000..39ac029 --- /dev/null +++ b/src/_apis/tool.ts @@ -0,0 +1,6 @@ +import { instance } from '@/_libs/api' + +export const getToolList = async () => { + const response = await instance.get(`/list`) + return response.data +} diff --git a/src/_libs/api.ts b/src/_libs/api.ts new file mode 100644 index 0000000..07c9bdc --- /dev/null +++ b/src/_libs/api.ts @@ -0,0 +1,22 @@ +import { API_BASE_URL } from '@/_constants/api' +import axios, { AxiosError, AxiosResponse } from 'axios' + +export const instance = axios.create({ + baseURL: API_BASE_URL, +}) + +function responsefulfilledInterceptor(res: AxiosResponse) { + if (200 <= res.status && res.status < 300) { + return res.data + } + return Promise.reject(res.data) +} + +function responseRejectedInterceptor(error: AxiosError) { + return error +} + +instance.interceptors.response.use( + responsefulfilledInterceptor, + responseRejectedInterceptor, +)