event API refract

using optimistic updates
This commit is contained in:
cv
2021-04-11 21:30:24 +02:00
parent 964bdf0d2a
commit 3db40be8a8
5 changed files with 144 additions and 26 deletions
+26 -5
View File
@@ -1,8 +1,29 @@
import axios from 'axios';
import { serverURL } from './apiConstants';
export const eventsURL = serverURL + 'events';
export const eventsNamespace = 'events';
export const eventsURL = serverURL + eventsNamespace;
export const fetchAllEvents = async () => {
const res = await fetch(eventsURL);
// TODO: Safe json convert
return res.json();
};
const res = await axios.get(eventsURL);
return res.data;
};
export const requestPost = async (data) => {
const res = await axios.post(eventsURL, data);
return res;
};
export const requestPut = async (data) => {
const res = await axios.put(eventsURL, data);
return res;
};
export const requestPatch = async (data) => {
const res = await axios.patch(eventsURL, data);
return res;
};
export const requestDelete = async (eventId) => {
const res = await axios.delete(eventsURL + '/' + eventId);
return res;
};