Back to Home

API Documentation

Complete guide to using the KarlJoke API. All endpoints are free and require no authentication.

📚Available Joke Types

general

General dad jokes and puns

500+ jokes

knock-knock

Classic knock-knock jokes

50+ jokes

programming

Developer and programming humor

100+ jokes

🔌API Endpoints

GET/api/jokes/random

Get a single random joke

curl https://karljoke.vercel.app/api/jokes/random
GET/api/jokes/ten

Get ten random jokes

curl https://karljoke.vercel.app/api/jokes/ten
GET/api/jokes/{number}

Get a specific number of random jokes

curl https://karljoke.vercel.app/api/jokes/5
GET/api/jokes/{type}/random

Get a random joke of a specific type

curl https://karljoke.vercel.app/api/jokes/programming/random
GET/api/jokes/{type}/ten

Get ten jokes of a specific type

curl https://karljoke.vercel.app/api/jokes/general/ten
GET/api/jokes/{type}/{number}

Get a specific number of jokes of a specific type

curl https://karljoke.vercel.app/api/jokes/knock-knock/3

📦Response Format

All endpoints return JSON with the following structure:

{
  "id": 1,
  "type": "general",
  "setup": "What did the fish say when it hit the wall?",
  "punchline": "Dam."
}
idUnique identifier for the joke
typeCategory of the joke (general, knock-knock, programming)
setupThe setup or question part of the joke
punchlineThe punchline or answer to the joke

⚡Quick Start Examples

JavaScript / TypeScript

// Fetch a random joke
const response = await fetch('https://karljoke.vercel.app/api/jokes/random');
const joke = await response.json();
console.log(joke.setup);
console.log(joke.punchline);

// Fetch 5 programming jokes
const response = await fetch('https://karljoke.vercel.app/api/jokes/programming/5');
const jokes = await response.json();
jokes.forEach(joke => console.log(joke.setup));

Python

import requests

# Fetch a random joke
response = requests.get('https://karljoke.vercel.app/api/jokes/random')
joke = response.json()
print(joke['setup'])
print(joke['punchline'])

# Fetch 3 knock-knock jokes
response = requests.get('https://karljoke.vercel.app/api/jokes/knock-knock/3')
jokes = response.json()
for joke in jokes:
    print(joke['setup'])

cURL

# Get a random joke
curl https://karljoke.vercel.app/api/jokes/random

# Get 10 general jokes
curl https://karljoke.vercel.app/api/jokes/general/10

# Get a programming joke
curl https://karljoke.vercel.app/api/jokes/programming/random

🤝Contributing

Want to add more jokes? We welcome contributions! Simply edit the source/jokes.json file with the following structure:

{
  "id": last joke id + 1,
  "type": "general",
  "setup": "Your joke setup here",
  "punchline": "Your punchline here"
}

Then open a pull request on GitHub. We'd love to have your contribution!

Open Pull Request