-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgh-api.js
44 lines (39 loc) · 1.02 KB
/
gh-api.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
/**
* @class : gh-api
* @author : Jason (casjaysdev@casjay.pro)
* @created : Thursday Jul 23, 2020 19:22:45 EDT
* @description : gh-api
*/
// GitHub API URL
const url = 'https://api.github.com/repos/onhealth/memes/contents/images';
// create an element
const createNode = (elem) => {
return document.createElement(elem);
};
// append an element to parent
const appendNode = (parent, elem) => {
parent.appendChild(elem);
}
// List Element
const ul = document.querySelector('#users');
// make the API call
fetch(url)
.then(res => res.json())
.then(data => {
console.log(data)
// iterate over users
data.map((user) => {
// create the elements
let li = createNode('li'),
img = createNode('img'),
span = createNode('span');
img.src = user.download_url;
span.innerText = user.name;
// append all elements
appendNode(li, img);
appendNode(li, span);
appendNode(ul, li);
});
}).catch(err => {
console.error('Error: ', err);
});