-
Notifications
You must be signed in to change notification settings - Fork 90
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
1 parent
96d0255
commit 2a40a3a
Showing
7 changed files
with
134 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
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,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.
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 @@ | ||
<!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> |
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 @@ | ||
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); | ||
}); | ||
}); |
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,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; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.