-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.js
More file actions
29 lines (25 loc) · 748 Bytes
/
Copy pathapi.js
File metadata and controls
29 lines (25 loc) · 748 Bytes
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
// Get json data from API, for example from: https://api.github.com/users/programandoconro
// Example 1
const callAPI = async () => {
const res = await fetch(" https://api.github.com/users/programandoconro");
const data = await res.json();
console.log(data);
const json = JSON.stringify(data);
document.write(json.bold());
};
// Example 2
const xhr = new XMLHttpRequest()
xhr.open('GET','https://api.github.com/users/programandoconro',true)
xhr.send()
xhr.responseText
// Example 3
const callAPI3 = () => {
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.github.com/users/programandoconro");
xhr.responseType = "json";
xhr.send();
xhr.onload = function () {
console.log(xhr.response);
};
};
callAPI3();