-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #375 from revanth1718/rev
Joke API added
- Loading branch information
Showing
6 changed files
with
210 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,17 @@ | ||
# Joke API Viewer App | ||
|
||
A simple web application to interact with the Joke API and display random jokes. | ||
|
||
## Features | ||
- Fetch and display random jokes | ||
- Deploy new Joke API apps | ||
- Scale Joke API app resources | ||
- Retrieve logs from Joke API apps | ||
|
||
## Installation | ||
1. Clone the repository: | ||
```bash | ||
git clone https://github.com/username/JokeAPIApp.git | ||
|
||
## Contributor | ||
### Revanth |
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,20 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="style.css"> | ||
<title>Joke API Viewer</title> | ||
</head> | ||
<body> | ||
<h1>Joke API Viewer</h1> | ||
<div id="app"> | ||
<h2>Random Joke</h2> | ||
<div id="joke"></div> | ||
<button id="fetchJokeButton">Fetch New Joke</button> | ||
|
||
</div> | ||
|
||
<script src="index.js"></script> | ||
</body> | ||
</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,53 @@ | ||
document.addEventListener('DOMContentLoaded', function () { | ||
fetchRandomJoke(); | ||
|
||
document.getElementById('fetchJokeButton').addEventListener('click', fetchRandomJoke); | ||
|
||
document.getElementById('deployButton').addEventListener('click', async () => { | ||
const appName = document.getElementById('deployAppName').value; | ||
const sourceUrl = document.getElementById('deploySourceUrl').value; | ||
const response = await fetch('/deploy', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ app_name: appName, source_url: sourceUrl }) | ||
}); | ||
const result = await response.json(); | ||
console.log(result); | ||
}); | ||
|
||
document.getElementById('scaleButton').addEventListener('click', async () => { | ||
const appName = document.getElementById('scaleAppName').value; | ||
const dynoType = document.getElementById('scaleDynoType').value; | ||
const quantity = document.getElementById('scaleQuantity').value; | ||
const response = await fetch('/scale', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ app_name: appName, dyno_type: dynoType, quantity: parseInt(quantity) }) | ||
}); | ||
const result = await response.json(); | ||
console.log(result); | ||
}); | ||
|
||
document.getElementById('logsButton').addEventListener('click', async () => { | ||
const appName = document.getElementById('logsAppName').value; | ||
const response = await fetch(`/logs?app_name=${appName}`); | ||
const result = await response.json(); | ||
const results = document.getElementById('results'); | ||
results.innerHTML = JSON.stringify(result, null, 2); | ||
}); | ||
}); | ||
|
||
async function fetchRandomJoke() { | ||
const endpoint = 'https://official-joke-api.appspot.com/random_joke'; | ||
|
||
fetch(endpoint) | ||
.then(response => response.json()) | ||
.then(data => { | ||
const joke = document.getElementById('joke'); | ||
joke.innerHTML = ` | ||
<p>${data.setup}</p> | ||
<p><strong>${data.punchline}</strong></p> | ||
`; | ||
}) | ||
.catch(error => console.error('Error fetching joke:', error)); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
{ | ||
"name": "joke-api-app", | ||
"version": "1.0.0", | ||
"description": "A simple app to view jokes from the Joke API", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node server.js" | ||
}, | ||
"author": "Your Name", | ||
"license": "ISC", | ||
"dependencies": { | ||
"express": "^4.17.1" | ||
} | ||
} | ||
|
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,60 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background: linear-gradient(135deg, #89fffd, #ef32d9); | ||
color: #fff; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
} | ||
|
||
h1 { | ||
font-size: 2.5em; | ||
margin-bottom: 20px; | ||
} | ||
|
||
#app { | ||
text-align: center; | ||
padding: 20px; | ||
background: rgba(0, 0, 0, 0.5); | ||
border-radius: 10px; | ||
} | ||
|
||
h2 { | ||
margin-top: 20px; | ||
font-size: 1.5em; | ||
} | ||
|
||
input, button { | ||
margin: 10px 0; | ||
padding: 10px; | ||
border-radius: 5px; | ||
border: none; | ||
} | ||
|
||
button { | ||
background: #ef32d9; | ||
color: #fff; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background: #a726c1; | ||
} | ||
|
||
#joke { | ||
margin: 20px 0; | ||
font-size: 1.2em; | ||
background: rgba(0, 0, 0, 0.3); | ||
padding: 10px; | ||
border-radius: 5px; | ||
} | ||
|
||
#setItem { | ||
margin-bottom: 15px; | ||
} | ||
|
||
#results { | ||
margin-top: 20px; | ||
} |