Files
todo/frontend/src/services/api.js
almazlar 37ae9dbe53
All checks were successful
Release and Build Docker Images / release-and-build (push) Successful in 1m29s
feat: Introduce application version display in the frontend footer, showing both frontend and backend versions with integrated build arguments.
2026-02-21 10:34:08 +03:00

44 lines
1.3 KiB
JavaScript

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();
};