32 lines
1002 B
JavaScript
32 lines
1002 B
JavaScript
export const fetchData = async(endpoints="", requestType="GET", requestBody=null)=>{
|
|
console.log("requestBody:", requestBody)
|
|
console.log("requestType:", requestType)
|
|
console.log("endpoints:", `https://192.168.99.121/${endpoints}`)
|
|
try{
|
|
const options={
|
|
method:requestType,
|
|
headers:{
|
|
"Content-Type":"application/json",
|
|
"Authorization": "ApiKey NS00TXlKUUIweUhWaGFuUUpUVTk6bWNVWXI1VXRSN2VWcFRtaEZ6NmdCUQ=="
|
|
}
|
|
}
|
|
|
|
if (requestType !=="GET" && requestBody){
|
|
options.body = JSON.stringify(requestBody)
|
|
}
|
|
|
|
const response = await fetch(`http://192.168.99.121/${endpoints}`, options)
|
|
console.log("response butrte: ", response)
|
|
if (!response.ok){
|
|
throw new Error(`HTTP error! Status: ${response.status}`)
|
|
}
|
|
|
|
return await response.json()
|
|
|
|
}
|
|
catch(error){
|
|
console.log("Fetch error:", error)
|
|
return null
|
|
}
|
|
|
|
} |