-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (25 loc) · 763 Bytes
/
index.js
File metadata and controls
27 lines (25 loc) · 763 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
import fetch from 'node-fetch';
let API = 'https://rickandmortyapi.com/api/character/';
function fetchData(url_api) {
return fetch(url_api)
.then( response => {
if(response.status == 200){
return response.json()
}
console.log(response)
})
.catch(error => {
console.error(error)
});
};
async function getData (){
const first = await fetchData(API);
const urlSecond = `${API}${first.results[0].id}`;
const second = await fetchData(urlSecond);
const urlThird = `${second.origin.url}`;
const third = await fetchData(urlThird);
console.log(`Personajes: ${first.info.count}`);
console.log(`Primer Personaje: ${second.name}`);
console.log(`Dimensión: ${third.dimension}`);
}
getData();