Skip to content

Commit

Permalink
Merge pull request #375 from revanth1718/rev
Browse files Browse the repository at this point in the history
Joke API added
  • Loading branch information
Kritika30032002 authored Aug 8, 2024
2 parents db9d3bc + b2bc1bf commit 19d2acd
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 0 deletions.
17 changes: 17 additions & 0 deletions New_APIs/Joke API/README.md
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
20 changes: 20 additions & 0 deletions New_APIs/Joke API/index.html
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>
53 changes: 53 additions & 0 deletions New_APIs/Joke API/index.js
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));
}
45 changes: 45 additions & 0 deletions New_APIs/Joke API/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions New_APIs/Joke API/package.json
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"
}
}

60 changes: 60 additions & 0 deletions New_APIs/Joke API/style.css
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;
}

0 comments on commit 19d2acd

Please sign in to comment.