Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Commit 8a8378e

Browse files
committed
add material
0 parents  commit 8a8378e

File tree

6 files changed

+154
-0
lines changed

6 files changed

+154
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# API Workshop Material

app.css

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
body {
2+
background: white;
3+
color: #323232;
4+
font-weight: 300;
5+
font-family: Helevtica neue, robot;
6+
}
7+
8+
.button {
9+
background-color: #4caf50; /* Green */
10+
border: none;
11+
color: white;
12+
padding: 15px 32px;
13+
text-align: center;
14+
text-decoration: none;
15+
display: inline-block;
16+
font-size: 16px;
17+
cursor: pointer;
18+
}

app.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
fetch ('https://api.github.com/users/dhvani35729')
2+
.then (response => response.json ())
3+
.then (data => {
4+
console.log (data);
5+
var greetingNode = document.getElementById ('greeting');
6+
greetingNode.innerHTML += ' ' + data.login + '!';
7+
var bioNode = document.getElementById ('userBio');
8+
bioNode.innerHTML = data.bio;
9+
var userImageNode = document.getElementById ('userImg');
10+
userImageNode.src = data.avatar_url;
11+
userImageNode.width = 200;
12+
});
13+
14+
function loadUsers () {
15+
console.log ('Loading users..');
16+
fetch ('https://reqres.in/api/users')
17+
.then (res => res.json ())
18+
.then (data => {
19+
console.log (data);
20+
var userTable = document.getElementById ('userTable');
21+
22+
data.data.forEach (user => {
23+
console.log (user.email);
24+
var newRow = userTable.insertRow ();
25+
var colId = document.createElement ('th');
26+
var colName = document.createElement ('th');
27+
var colEmail = document.createElement ('th');
28+
let textId = document.createTextNode (user.id);
29+
let textName = document.createTextNode (user.first_name);
30+
let textEmail = document.createTextNode (user.email);
31+
colId.appendChild (textId);
32+
colName.appendChild (textName);
33+
colEmail.appendChild (textEmail);
34+
newRow.appendChild (colId);
35+
newRow.appendChild (colName);
36+
newRow.appendChild (colEmail);
37+
});
38+
});
39+
}
40+
41+
function sendSwit () {
42+
console.log ('Sending message to Swit');
43+
var inputText = document.getElementById ('message').value;
44+
fetch ('https://hook.swit.io/chat/200326205355708CTEB/ntq1pBDDQqf3ne3NgZFL', {
45+
method: 'POST',
46+
headers: {
47+
'Content-Type': 'application/json',
48+
},
49+
body: JSON.stringify ({
50+
text: inputText,
51+
}),
52+
})
53+
.then (res => res.json ())
54+
.then (data => console.log (data));
55+
56+
return false;
57+
}

bot.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# importing the requests library
2+
import requests
3+
import json
4+
from threading import Timer
5+
6+
7+
def askData():
8+
Timer(1.0, askData).start()
9+
10+
API_ENDPOINT = "https://hook.swit.io/chat/200328231505006C9sA/FihS4PXQOpHrBcc5lWm7"
11+
12+
data = {'text':"I want data"}
13+
14+
r = requests.post(url = API_ENDPOINT, json=data)
15+
16+
print(r)
17+
18+
askData()

index.html

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<link rel="stylesheet" href="app.css">
6+
</head>
7+
8+
<body>
9+
10+
<h2 id="greeting">
11+
Hey there,
12+
</h2>
13+
<p id="userBio">
14+
</p>
15+
<img id="userImg">
16+
17+
<hr />
18+
<buttton class="button" onclick="loadUsers()">Load Users</buttton>
19+
20+
<table id="userTable">
21+
<thead>
22+
<tr>
23+
<th>id</th>
24+
<th>name</th>
25+
<th>emal</th>
26+
</tr>
27+
</thead>
28+
<tbody>
29+
30+
</tbody>
31+
</table>
32+
33+
<hr />
34+
<form onsubmit="return sendSwit()">
35+
<label>Message:</label><br>
36+
<input type="text" id="message" value=""><br>
37+
<input type="submit" value="Submit">
38+
</form>
39+
40+
41+
</body>
42+
43+
<script src="app.js"></script>
44+
45+
</html>

index.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const express = require ('express');
2+
const app = express ();
3+
4+
const port = 3000;
5+
6+
app.get ('/', (req, res) => {
7+
// res.send ('Hello World!');
8+
res.status (200).json ({
9+
message: 'It works!',
10+
});
11+
});
12+
13+
app.listen (port, () =>
14+
console.log ('Starting server on http://localhost:' + port)
15+
);

0 commit comments

Comments
 (0)