This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
57 lines (56 loc) · 1.8 KB
/
index.html
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
57
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Example with kinka</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/npm/kinka@latest/dist/kinka.min.js"></script>
<style>
body{
display: flex;
flex-direction: column;
justify-content: center;
margin: 0;
height: 100vh;
width: 100vw;
text-align: center;
}
.find-user-form{
position: absolute;
left: 50%;
transform: translateX(-50%) translateY(-80%);
top: 20%;
}
</style>
</head>
<body>
<form onsubmit="findUser()" class="find-user-form">
<header>Find user by ID in reqres.in</header>
<input id="user-id" placeholder="2"/>
<button type="submit">Find!</button>
</form>
<div class="user">
<label id="first-name"></label>
<label id="last-name"></label>
<img id="user-avatar"/>
</div>
<script>
var el = function(query) { return document.querySelector(query) }
var api = kinka.create({
baseURL: 'https://reqres.in/api',
})
function findUser(){
window.event.preventDefault()
api.get('/users/' + el('#user-id').value).then(function(response){
if(response.err) return alert('occured an error ', response.err)
var user = response.data.data
el('#first-name').innerText = user.first_name
el('#last-name').innerText = user.last_name
el('#user-avatar').setAttribute('src', user.avatar)
})
return false
}
</script>
</body>
</html>