Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

api.ts

15 lines557 Bytes

1export const todosAPI = {
2 getTodos: async (): Promise<Array<string>> => {
3 const response = await fetch('/api/data')
4 if (!response.ok) throw new Error('Failed to fetch todos')
5 return await response.json()
6 },
7 createTodo: async (add: string) => {
8 const response = await fetch(`/api/data?add=${encodeURIComponent(add)}`)
9 if (!response.ok) throw new Error('Failed to add todo')
10 },
11 deleteTodos: async () => {
12 const response = await fetch(`/api/data?clear=1`)
13 if (!response.ok) throw new Error('Failed to clear todos')
14 },