1fetch('https://api.github.com/users/manishmshiva', {
2 method: "GET",
3 headers: {"Content-type": "application/json;charset=UTF-8"}
4})
5.then(response => response.json())
6.then(json => console.log(json));
7.catch(err => console.log(err));
1function createNode(element) {
2 return document.createElement(element);
3}
4
5function append(parent, el) {
6 return parent.appendChild(el);
7}
8
9const ul = document.getElementById('authors');
10const url = 'https://randomuser.me/api/?results=10';
11
12fetch(url)
13.then((resp) => resp.json())
14.then(function(data) {
15 let authors = data.results;
16 return authors.map(function(author) {
17 let li = createNode('li');
18 let img = createNode('img');
19 let span = createNode('span');
20 img.src = author.picture.medium;
21 span.innerHTML = `${author.name.first} ${author.name.last}`;
22 append(li, img);
23 append(li, span);
24 append(ul, li);
25 })
26})
27.catch(function(error) {
28 console.log(error);
29});