1
0
Fork 0
mirror of synced 2024-09-15 00:38:01 +12:00
budibase/packages/builder/src/builderStore/api.js

31 lines
593 B
JavaScript
Raw Normal View History

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