()
| 38 | // API client that calls the shared backend server |
| 39 | export const todoApi = { |
| 40 | async getAll(): Promise<Array<Todo>> { |
| 41 | const response = await fetch(`${BASE_URL}/api/todos`) |
| 42 | if (!response.ok) { |
| 43 | throw new Error(`Failed to fetch todos: ${response.status}`) |
| 44 | } |
| 45 | const data: Array<TodoResponse> = await response.json() |
| 46 | return data.map(parseTodo) |
| 47 | }, |
| 48 | |
| 49 | async create(data: { |
| 50 | id?: string |