Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random Joke API #254

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Existing_API_Collection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
|[Cricket API](./Cricket_Score_API/)| this api gives all the current matches and upcoming matches also give scores of current matches and gives players list |
|[NewsBuster](./news-buster-api/)|This API helps you gain worldly knowledge with a better frontend by fetching API |
|[TranslatorAPI](./TranslatorAPI/)|This API helps to translate text with OTHER languages|
Certainly! Here's an entry for your Random Joke API:
|[Random Joke API](./Random_Joke_api/) | This API provides a wide range of jokes, including single-line jokes and jokes with setups and punchlines. |
|[JSON_Placeholder_API](./JSON_Plaeholder_API/)| this api is used to test basic crud operations on fake data posts |
|[Gold Silver Price](./Gold,silver_price_API/)|This API helps you check realtime price of gold and silver for each categories |
|[GeoAPI](./GeoAPI/)| GeoAPI is a simple RESTful API that allows you to convert addresses to geographic coordinates (latitude and longitude) and vice versa. This API is built using Node.js and Express.|
Expand Down
46 changes: 46 additions & 0 deletions Existing_API_Collection/Random_Joke_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Random Joke API

Welcome to the Random Joke API! This API is designed to bring humor into your applications by providing a wide range of jokes. Whether you need a quick one-liner or a setup with a punchline, this API has got you covered!

## Features
- **Random Jokes:** Fetch jokes randomly from various categories, including programming, miscellaneous, and more.
- **Single-Line and Two-Part Jokes:** Get both single-line jokes and jokes with setups and punchlines.
- **Error Handling:** Robust error handling ensures informative error messages for smooth integration.
- **Simple Integration:** Easy-to-use API interface makes integration seamless.

## Technologies Used
- Node.js
- Express.js
- JavaScript
- RESTful API design principles

# API Integration
This API can be integrated into your application by making HTTP requests to the following endpoint:

```
GET https://v2.jokeapi.dev/joke/Any
```

Replace `Any` in the endpoint with the desired category of the joke. Available categories include `Any`, `Miscellaneous`, `Programming`, `Pun`, `Spooky`, `Christmas`, and more.

## Installation
To set up the Random Joke API locally, follow these steps:

- Clone the repository
- Navigate to the RandomJokeAPI folder
- Install dependencies with `npm install`
- Start the server with `npm start`
- The API will be accessible at `http://localhost:3000`

## Usage
To fetch a random joke, make a GET request to the endpoint specified above. The API will respond with a JSON object containing the joke.

Example Request:
```
GET https://v2.jokeapi.dev/joke/Any
```


## Screenshots
![Random Joke API](assets/image.png)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions Existing_API_Collection/Random_Joke_api/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Joke Generator</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>Random Joke Generator</h1>
<button id="getJoke">Get a Joke</button>
<p id="joke"></p>
</div>
<script src="script.js"></script>
</body>
</html>
17 changes: 17 additions & 0 deletions Existing_API_Collection/Random_Joke_api/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
document.getElementById('getJoke').addEventListener('click', function() {
const apiUrl = 'https://v2.jokeapi.dev/joke/Any';

fetch(apiUrl)
.then(response => response.json())
.then(data => {
const jokeElement = document.getElementById('joke');
if (data.type === 'single') {
jokeElement.textContent = data.joke;
} else {
jokeElement.textContent = `${data.setup} - ${data.delivery}`;
}
})
.catch(error => {
console.error('Error fetching the joke:', error);
});
});
46 changes: 46 additions & 0 deletions Existing_API_Collection/Random_Joke_api/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #f0f0f0;
}

.container {
background: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
}

h1 {
color: #333333;
margin-bottom: 20px;
}

button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #007bff;
color: #ffffff;
border: none;
border-radius: 4px;
transition: background-color 0.3s ease;
}

button:hover {
background-color: #0056b3;
}

button:focus {
outline: none;
}

#joke {
margin-top: 20px;
font-size: 18px;
color: #555555;
}
6 changes: 6 additions & 0 deletions package-lock.json

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

Loading