File size: 693 Bytes
cce8120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import axios from 'axios';
import { Todo } from './App';

const api = axios.create({
  baseURL: '/api',
});

export const fetchTodos = async (): Promise<Todo[]> => {
  const response = await api.get<Todo[]>('/todos/');
  return response.data;
};

export const createTodo = async (todo: Omit<Todo, 'id'>): Promise<Todo> => {
  const response = await api.post<Todo>('/todos/', todo);
  return response.data;
};

export const updateTodo = async (id: number, todo: Omit<Todo, 'id'>): Promise<Todo> => {
  const response = await api.put<Todo>(`/todos/${id}`, todo);
  return response.data;
};

export const deleteTodo = async (id: number): Promise<void> => {
  await api.delete(`/todos/${id}`);
};