-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync.js
More file actions
56 lines (45 loc) · 1.2 KB
/
async.js
File metadata and controls
56 lines (45 loc) · 1.2 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
const promessa = new Promise(function(resolve, reject){
return reject('error')
//return resolve('deu bom')
})
async function start() {
try{
const result = await promessa
console.log(result)
} catch(e){
console.log(e)
}finally {
console.log('acabou')
}
}
start()
async function apiCall() {
try {
const response = await fetch("https://api.github.com/users/vitor115");
const user = await response.json();
const reposResponse = await fetch(user.repos_url);
const repos = await reposResponse.json();
console.log(repos);
} catch (e) {
console.log(e);
}
}
apiCall();
async function apiCall2() {
const url = "https://api.github.com/users/vitor115";
const user = await fetch(url).then(r =>r.json);
const userRepos = await fetch(user.repos_url).then(r => r.json());
console.log(userRepos);
}
apiCall2().catch(e =>console.log(e));
import axios from "axios";
async function fetchRepos(){
try{
const user = await axios.get("https://api.github.com/users/vitor115")
const repos = await axios.get(user.data.repos_url)
console.log(repos.data)
}catch(e){
console.log(e)
}
}
fetchRepos()