프론트엔드/프론트엔드 이슈
API 요청 함수
syleemomo
2024. 5. 20. 15:14
728x90
async function connectData(url, method, data = null, token = null){
const dataJson = await fetch(url,{
headers:{
'Content-Type':'application/json',
'Authorization': `${token? 'Bearer' + token : ''}`,
},
method: method,
body: data? data : null
})
const result = await dataJson.json()
return result
}
API 데이터 요청하는 유틸리티 함수입니다. utils 폴더 생성하고, api.js 파일에 작성한 다음 필요한 컴포넌트에서 사용하면 된다.
728x90