-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
43 lines (39 loc) · 1.19 KB
/
api.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const baseUrl = 'http://10.0.2.2:3000/tasks'; //10.0.2.2
const getTasks = async () => {
const response = await fetch(baseUrl);
const Tasks = await response.json();
return Tasks;
}
const addTask = async () => {
const response = await fetch(baseUrl, {
method: 'Task',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(Task),
});
const TaskToAdd = await response.json();
return TaskToAdd;
}
const updateTask = async () => {
const response = await fetch(`${baseUrl}/${Task.id}`, {
method: 'PUT',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(Task),
});
const TaskToUpdate = await response.json();
return TaskToUpdate;
}
const deleteTask = async () => {
return await fetch(`${baseUrl}/${id}`, { method: 'DELETE' });
}
export const api = {
getTasks,
addTask,
updateTask,
deleteTask
};