This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8a8378e
Showing
6 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# API Workshop Material |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
body { | ||
background: white; | ||
color: #323232; | ||
font-weight: 300; | ||
font-family: Helevtica neue, robot; | ||
} | ||
|
||
.button { | ||
background-color: #4caf50; /* Green */ | ||
border: none; | ||
color: white; | ||
padding: 15px 32px; | ||
text-align: center; | ||
text-decoration: none; | ||
display: inline-block; | ||
font-size: 16px; | ||
cursor: pointer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
fetch ('https://api.github.com/users/dhvani35729') | ||
.then (response => response.json ()) | ||
.then (data => { | ||
console.log (data); | ||
var greetingNode = document.getElementById ('greeting'); | ||
greetingNode.innerHTML += ' ' + data.login + '!'; | ||
var bioNode = document.getElementById ('userBio'); | ||
bioNode.innerHTML = data.bio; | ||
var userImageNode = document.getElementById ('userImg'); | ||
userImageNode.src = data.avatar_url; | ||
userImageNode.width = 200; | ||
}); | ||
|
||
function loadUsers () { | ||
console.log ('Loading users..'); | ||
fetch ('https://reqres.in/api/users') | ||
.then (res => res.json ()) | ||
.then (data => { | ||
console.log (data); | ||
var userTable = document.getElementById ('userTable'); | ||
|
||
data.data.forEach (user => { | ||
console.log (user.email); | ||
var newRow = userTable.insertRow (); | ||
var colId = document.createElement ('th'); | ||
var colName = document.createElement ('th'); | ||
var colEmail = document.createElement ('th'); | ||
let textId = document.createTextNode (user.id); | ||
let textName = document.createTextNode (user.first_name); | ||
let textEmail = document.createTextNode (user.email); | ||
colId.appendChild (textId); | ||
colName.appendChild (textName); | ||
colEmail.appendChild (textEmail); | ||
newRow.appendChild (colId); | ||
newRow.appendChild (colName); | ||
newRow.appendChild (colEmail); | ||
}); | ||
}); | ||
} | ||
|
||
function sendSwit () { | ||
console.log ('Sending message to Swit'); | ||
var inputText = document.getElementById ('message').value; | ||
fetch ('https://hook.swit.io/chat/200326205355708CTEB/ntq1pBDDQqf3ne3NgZFL', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify ({ | ||
text: inputText, | ||
}), | ||
}) | ||
.then (res => res.json ()) | ||
.then (data => console.log (data)); | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# importing the requests library | ||
import requests | ||
import json | ||
from threading import Timer | ||
|
||
|
||
def askData(): | ||
Timer(1.0, askData).start() | ||
|
||
API_ENDPOINT = "https://hook.swit.io/chat/200328231505006C9sA/FihS4PXQOpHrBcc5lWm7" | ||
|
||
data = {'text':"I want data"} | ||
|
||
r = requests.post(url = API_ENDPOINT, json=data) | ||
|
||
print(r) | ||
|
||
askData() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<link rel="stylesheet" href="app.css"> | ||
</head> | ||
|
||
<body> | ||
|
||
<h2 id="greeting"> | ||
Hey there, | ||
</h2> | ||
<p id="userBio"> | ||
</p> | ||
<img id="userImg"> | ||
|
||
<hr /> | ||
<buttton class="button" onclick="loadUsers()">Load Users</buttton> | ||
|
||
<table id="userTable"> | ||
<thead> | ||
<tr> | ||
<th>id</th> | ||
<th>name</th> | ||
<th>emal</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
|
||
</tbody> | ||
</table> | ||
|
||
<hr /> | ||
<form onsubmit="return sendSwit()"> | ||
<label>Message:</label><br> | ||
<input type="text" id="message" value=""><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
|
||
|
||
</body> | ||
|
||
<script src="app.js"></script> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const express = require ('express'); | ||
const app = express (); | ||
|
||
const port = 3000; | ||
|
||
app.get ('/', (req, res) => { | ||
// res.send ('Hello World!'); | ||
res.status (200).json ({ | ||
message: 'It works!', | ||
}); | ||
}); | ||
|
||
app.listen (port, () => | ||
console.log ('Starting server on http://localhost:' + port) | ||
); |