-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
57 lines (51 loc) · 1.22 KB
/
api.js
File metadata and controls
57 lines (51 loc) · 1.22 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Модуль api.js
const todosURL = "https://wedev-api.sky.pro/api/v2/todos";
const userURL = "https://wedev-api.sky.pro/api/user/login";
export let token;
export const setToken = (newToken) => {
token = newToken;
};
export function getTodos() {
return fetch(todosURL, {
method: "GET",
headers: {
Authorization: 'Bearer ${token}',
},
}).then((response) => {
return response.json();
});
}
export function deleteTodo({ id }) {
return fetch('${todosURL}/${id}', {
method: "DELETE",
headers: {
Authorization: 'Bearer ${token}',
},
}).then((response) => {
return response.json();
});
}
export function postTodo({ text }) {
return fetch(todosURL, {
method: "POST",
headers: {
Authorization: 'Bearer ${token}',
},
body: JSON.stringify({
text,
}),
}).then((response) => {
return response.json();
});
}
export function login({ login, password }) {
return fetch(userURL, {
method: "POST",
body: JSON.stringify({
login,
password,
}),
}).then((response) => {
return response.json();
});
}