67 lines
1.6 KiB
TypeScript
67 lines
1.6 KiB
TypeScript
//8880
|
|
|
|
import { DEV_URL_FO, DEV_URL_WR } from "../config/";
|
|
|
|
export const fetchType={COMMON: "common", WR: "wr"}
|
|
|
|
export const getFetch = async( type:string , url: string) => {
|
|
const div = type === fetchType.COMMON ? DEV_URL_FO : DEV_URL_WR
|
|
const response = await fetch( div+url , {
|
|
method: "GET",
|
|
headers: {
|
|
accept: "application/json",
|
|
},
|
|
});
|
|
|
|
if(!response.ok) {
|
|
throw new Error(`오류 발생: ${response.status}`);
|
|
}
|
|
const res = await response.json()
|
|
return res.data;
|
|
}
|
|
|
|
export const postFectch = async (url: string, params: any) => {
|
|
|
|
const response = await fetch(DEV_URL_WR+url, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(params),
|
|
});
|
|
if(!response.ok) {
|
|
throw new Error(`오류 발생: ${response.status}`);
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
export const putFectch = async (url: string, params: any) => {
|
|
|
|
const response = await fetch(DEV_URL_WR+url, {
|
|
method: "PUT",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(params),
|
|
});
|
|
if(!response.ok) {
|
|
throw new Error(`오류 발생: ${response.status}`);
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
export const deleteFectch = async (url: string, params: any) => {
|
|
const response = await fetch(DEV_URL_WR+url, {
|
|
method: "DELETE",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(params),
|
|
});
|
|
if(!response.ok) {
|
|
throw new Error(`오류 발생: ${response.status}`);
|
|
}
|
|
return response;
|
|
}
|