Dad Jokes API Instructions

This document provides instructions on how to use the Dad Jokes API.

API Endpoints

Get Random Joke

Retrieve a random dad joke from the database.

GET /api/v2/random

Example Request (using curl):

curl https://dadjokes.developersandbox.xyz/api/v2/random

Example Success Response (JSON):

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

Example Empty Table Response (JSON):

{
    "message": "No jokes found in the database."
}

Submit New Joke

Submit a new dad joke to the database.

POST /api/v2/submit

Content-Type: application/json

Example Request Body (JSON):

{
    "author": "Jane Doe",
    "joke_text": "Why don't programmers like nature? It has too many bugs!"
}

Example Request (using curl):

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

Example Success Response (JSON):

{
    "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!"
}

Source Code

The source code for this API can be found on GitHub: https://github.com/andrewthecodertx/go-dadjokes-api