Skip to content

Commit

Permalink
[#1] api 기초 세팅
Browse files Browse the repository at this point in the history
  • Loading branch information
hanseulhee committed May 4, 2024
1 parent 163fd06 commit 3caa852
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/_apis/tool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { instance } from '@/_libs/api'

export const getToolList = async () => {
const response = await instance.get(`/list`)
return response.data
}
22 changes: 22 additions & 0 deletions src/_libs/api.ts
Original file line number Diff line number Diff line change
@@ -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,
)

0 comments on commit 3caa852

Please sign in to comment.