2020-04-28 15:39:35 +02:00
|
|
|
const apiCall = method => async (url, body) => {
|
2020-05-06 21:29:47 +02:00
|
|
|
const jwt = localStorage.getItem("budibase:token");
|
|
|
|
|
2020-04-28 15:39:35 +02:00
|
|
|
const response = await fetch(url, {
|
2020-02-03 10:24:25 +01:00
|
|
|
method: method,
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
2020-05-06 21:29:47 +02:00
|
|
|
"Authorization": `Bearer ${jwt}`
|
2020-02-03 10:24:25 +01:00
|
|
|
},
|
|
|
|
body: body && JSON.stringify(body),
|
|
|
|
})
|
2019-07-28 09:03:11 +02:00
|
|
|
|
2020-04-28 15:39:35 +02:00
|
|
|
// if (response.status === 500) {
|
|
|
|
// throw new Error("Server Error");
|
|
|
|
// }
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const post = apiCall("POST")
|
|
|
|
const get = apiCall("GET")
|
|
|
|
const patch = apiCall("PATCH")
|
|
|
|
const del = apiCall("DELETE")
|
2019-07-28 09:03:11 +02:00
|
|
|
|
|
|
|
export default {
|
2020-02-03 10:24:25 +01:00
|
|
|
post,
|
|
|
|
get,
|
|
|
|
patch,
|
|
|
|
delete: del,
|
|
|
|
}
|