-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
104 lines (82 loc) · 2.79 KB
/
app.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Fetch API Example
// Fetch API From Text File
document.querySelector('#button1').addEventListener('click', getText);
function getText() {
fetch('data.txt')
.then(responce => responce.text())
.then(data => document.querySelector('#output').innerHTML = data)
.catch(err => document.querySelector('#output').innerHTML = err);
}
// Fetch API From Json File
document.querySelector('#button2').addEventListener('click', getJSON);
function getJSON() {
fetch('custmer.json')
.then(responce => responce.json())
.then(data => {
let output = '';
data.forEach(post => {
output += `
<li>${post.title}</li>
`;
});
document.querySelector('#output').innerHTML = output;
})
.catch(err => document.querySelector('#output').innerHTML = err);
}
// Fetch API From API URL
document.querySelector('#button3').addEventListener('click', getAPI);
function getAPI() {
fetch('https://api.github.com/users')
.then(responce => responce.json())
.then(data => {
let output = '';
data.forEach(function (post) {
output += `
<li>${post.login}</li>
`;
});
document.querySelector('#output').innerHTML = output;
})
.catch(err => document.querySelector('#output').innerHTML = err);
}
// initliaize EasyHTTP Object
const http = new EasyHTTP();
// Get Posts
http.get('https://jsonplaceholder.typicode.com/users')
.then(data => console.log(data))
.catch(err => console.log(err));
const data = {
name: 'Jhon',
username: 'Jhon',
email: 'Jhon',
}
// Post new User
http.post('https://jsonplaceholder.typicode.com/users', data)
.then(data => console.log(data))
.catch(err => console.log(err));
// Update User
http.put('https://jsonplaceholder.typicode.com/users/1', data)
.then(data => console.log(data))
.catch(err => console.log(err));
// Delete User
http.delete('https://jsonplaceholder.typicode.com/users/1')
.then(data => console.log(data))
.catch(err => console.log(err));
// initliaize EasyHTTP2 Object
const http2 = new EasyHTTP3();
// Get Posts
http2.get('https://jsonplaceholder.typicode.com/users')
.then(data => console.log(data))
.catch(err => console.log(err));
// Post new User
http2.post('https://jsonplaceholder.typicode.com/users', data)
.then(data => console.log(data))
.catch(err => console.log(err));
// Update User
http2.put('https://jsonplaceholder.typicode.com/users/1', data)
.then(data => console.log(data))
.catch(err => console.log(err));
// Delete User
http2.delete('https://jsonplaceholder.typicode.com/users/1')
.then(data => console.log(data))
.catch(err => console.log(err));