$ dad-jokes-api

A free, no-key REST API for dad jokes. Fetch a random joke, or submit your own to the collection. Written in Go, backed by PostgreSQL.

### base url

All endpoints are relative to this base URL:

https://andrewthecoder.com/api/v2

### get a random joke

Returns a random joke from the database.

[GET]/api/v2/randomjoke

curl

curl https://andrewthecoder.com/api/v2/randomjoke

response

{
  "id": 1,
  "entry_date": "2024-01-06T12:00:00Z",
  "author": "John Doe",
  "joke_text": "Why don't eggs tell jokes? They'd crack up!"
}

If the database is empty, you'll get a404 with"No jokes found in the database."

### submit a joke

Adds a joke to the collection. Rate-limited per IP.

[POST]/api/v2/writejoke— Content-Type: application/json

curl

curl -X POST https://andrewthecoder.com/api/v2/writejoke \
  -H "Content-Type: application/json" \
  -d '{"author": "Jane Doe", "joke_text": "Why don't programmers like nature? It has too many bugs!"}'

response

{
  "id": 2,
  "entry_date": "2024-01-06T12:01:00Z",
  "author": "Jane Doe",
  "joke_text": "Why don't programmers like nature? It has too many bugs!"
}

Validation rules:

  • author — required, max 255 characters
  • joke_text — required, max 2000 characters

### errors

  • 400 Bad Request — missing or invalid fields, e.g. "Author cannot be empty."
  • 404 Not Found — no jokes in the database yet
  • 429 Too Many Requests — submission rate limit exceeded
  • 500 Internal Server Error — something broke on our end

### rate limits

POST /api/v2/writejoke is rate-limited per IP: a burst of 3 requests, refilling at 1 request per second.

GET /api/v2/randomjoke is unlimited.

### source code

The API is open source (MIT). Contribute a joke or report an issue on GitHub:

github.com/andrewthecodertx/go-dadjokes-api