Scalino84
Initial commit
1e7308f
raw
history blame
1.91 kB
// static/components/api.js
export const API = {
albums: {
list: '/albums', // Vermutung basierend auf AlbumManager.js
create: '/create_album',
delete: (id) => `/delete_album/${id}`,
update: (id) => `/update_album/${id}`,
},
categories: {
list: '/categories', // Vermutung basierend auf CategoryManager.js
create: '/create_category',
delete: (id) => `/delete_category/${id}`,
update: (id) => `/update_category/${id}`,
merge: '/categories/merge'
},
statistics: {
images: '/backend/stats',
storage: '/backend/stats'
}
};
export const APIHandler = {
get: async (url) => {
const response = await fetch(url);
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
},
post: async (url, data) => {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
},
put: async (url, data) => {
//PUT hinzufügen
const response = await fetch(url, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
},
delete: async (url) => {
const response = await fetch(url, {
method: 'DELETE'
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
}
};