2020-04-28 15:39:35 +02:00
|
|
|
const apiCall = method => async (url, body) => {
|
|
|
|
const response = await fetch(url, {
|
2020-02-03 10:24:25 +01:00
|
|
|
method: method,
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
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");
|
|
|
|
// }
|
|
|
|
|
2020-05-07 11:53:34 +02:00
|
|
|
return response
|
2020-04-28 15:39:35 +02:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
}
|