From 3caa85226bbc42212bc93d91530a374a6b11d887 Mon Sep 17 00:00:00 2001 From: hanseulhee <3021062@gmail.com> Date: Sat, 4 May 2024 23:29:51 +0900 Subject: [PATCH] =?UTF-8?q?[#1]=20api=20=EA=B8=B0=EC=B4=88=20=EC=84=B8?= =?UTF-8?q?=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/_apis/tool.ts | 6 ++++++ src/_libs/api.ts | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/_apis/tool.ts create mode 100644 src/_libs/api.ts 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, +)