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

28 lines
499 B
JavaScript
Raw Normal View History

const apiCall = method => async (url, body) => {
const response = await fetch(url, {
method: method,
headers: {
"Content-Type": "application/json",
},
body: body && JSON.stringify(body),
})
2019-07-28 09:03:11 +02: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 09:03:11 +02:00
export default {
post,
get,
patch,
delete: del,
}