budibase/packages/builder/src/builderStore/api.js

31 lines
609 B
JavaScript
Raw Normal View History

const apiCall = method => async (url, body) => {
const response = await fetch(url, {
method: method,
headers: {
"Content-Type": "application/json",
2020-06-03 20:35:04 +02:00
"x-user-agent": "Budibase Builder",
},
body: body && JSON.stringify(body),
})
2019-07-28 09:03:11 +02:00
// if (response.status === 500) {
// throw new Error("Server Error");
// }
2020-05-07 11:53:34 +02:00
return response
}
export const post = apiCall("POST")
export const get = apiCall("GET")
export const patch = apiCall("PATCH")
export const del = apiCall("DELETE")
export const put = apiCall("PUT")
2019-07-28 09:03:11 +02:00
export default {
post,
get,
patch,
delete: del,
put,
}