const BASE_URL = 'https://todo.almazlar.com/api/todos'; export const getTodos = async () => { const response = await fetch(BASE_URL); if (!response.ok) throw new Error('Failed to fetch todos'); return response.json(); }; export const createTodo = async (todo) => { const response = await fetch(BASE_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(todo), }); if (!response.ok) throw new Error('Failed to create todo'); return response.json(); }; export const updateTodo = async (id, todo) => { const response = await fetch(`${BASE_URL}/${id}`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(todo), }); if (!response.ok) throw new Error('Failed to update todo'); return response.json(); }; export const deleteTodo = async (id) => { const response = await fetch(`${BASE_URL}/${id}`, { method: 'DELETE', }); if (!response.ok) throw new Error('Failed to delete todo'); return true; }; export const getVersion = async () => { // Use the origin to ensure it accesses the /api/version correctly regardless of environment const VERSION_URL = BASE_URL.replace('/todos', '/version'); const response = await fetch(VERSION_URL); if (!response.ok) throw new Error('Failed to fetch version'); return response.json(); };