-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-2.html
43 lines (41 loc) · 1.05 KB
/
example-2.html
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
<!DOCTYPE HTML>
<html>
<head>
<script src="sugar.js"></script>
</head>
<body>
<script>
sugar(() => {
var ENDPOINT = 'api/todos'
var todo = {
"text": "thing to todo"
}
/*
* POST api/todos - create a todo
*/
fetch(ENDPOINT, {
method: 'POST',
body: JSON.stringify(todo)
})
.then(response => response.json())
.then(todo => {
/*
* GET api/todo/{id} - retrieve the todo by id
*/
fetch(`${ENDPOINT}/${todo.id}`)
.then(response => response.json())
.then(todo => {
console.log(todo)
/*
output:
{
"text": "thing to todo",
"id": 1
}
*/
})
})
})
</script>
</body>
</html>