feat: Add initial frontend dependencies, base CSS, and Gitea Docker build workflow.
Some checks failed
Build and Push Docker Images / build-and-push (push) Failing after 2m23s
Some checks failed
Build and Push Docker Images / build-and-push (push) Failing after 2m23s
This commit is contained in:
35
frontend/src/services/api.js
Normal file
35
frontend/src/services/api.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const BASE_URL = 'http://localhost:8082/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;
|
||||
};
|
||||
Reference in New Issue
Block a user