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

23 lines
641 B
JavaScript
Raw Normal View History

2019-08-19 22:18:23 +02:00
import { isUndefined } from "lodash/fp";
2019-07-28 09:03:11 +02:00
2019-08-19 22:18:23 +02:00
const apiCall = (method, returnJson) => (url, body, returnJsonOverride) =>
2019-07-28 09:03:11 +02:00
fetch(url, {
method: method,
headers: {
'Content-Type': 'application/json',
},
body: body && JSON.stringify(body),
2019-08-19 22:18:23 +02:00
}).then(r => {
if(!isUndefined(returnJsonOverride))
returnJson = returnJsonOverride;
return returnJson ? r.json() : r
});
2019-07-28 09:03:11 +02:00
2019-08-19 09:51:01 +02:00
const post = apiCall("POST", true);
const get = apiCall("GET", true);
const patch = apiCall("PATCH", true);
const del = apiCall("DELETE", false);
2019-07-28 09:03:11 +02:00
export default {
post, get, patch, delete:del
};