climbing-dashboard / src /utils /storage.js
lewtun's picture
lewtun HF Staff
Persist
a2ef1ee
raw
history blame contribute delete
910 Bytes
async function request(path, options = {}) {
const response = await fetch(path, {
headers: {
'Content-Type': 'application/json',
...(options.headers || {}),
},
...options,
});
if (!response.ok) {
throw new Error(`API ${response.status}: ${response.statusText}`);
}
if (response.status === 204) return null;
return response.json();
}
export async function loadSessions() {
return request('/api/sessions');
}
export async function createSession(session) {
return request('/api/sessions', {
method: 'POST',
body: JSON.stringify(session),
});
}
export async function updateSession(id, changes) {
return request(`/api/sessions/${encodeURIComponent(id)}`, {
method: 'PUT',
body: JSON.stringify(changes),
});
}
export async function deleteSession(id) {
return request(`/api/sessions/${encodeURIComponent(id)}`, {
method: 'DELETE',
});
}