clbo/joke-service

By clbo

Updated 4 months ago

Microservice used for teachings at 3rd semester ITA at Kea

Image
API Management
0

251

Joke Service

A simple microservice that serves jokes through RESTful API endpoints.

Description

This service provides various endpoints to retrieve jokes, including options to get all jokes, a random joke, or a specific joke by ID.

Setup

Running with Docker
  1. Build the Docker image:
docker build -t joke-service .
  1. Run the container:
docker run -p 5000:80 joke-service
Running without Docker
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the application:
python app.py

The service will be available at http://localhost:5000

API Endpoints

Get All Jokes
  • URL: /api/jokes
  • Method: GET
  • Response: Array of joke objects
[
    {
        "id": 1,
        "setup": "Why don't programmers like nature?",
        "punchline": "It has too many bugs!"
    },
    {
        "id": 2,
        "setup": "What do you call a bear with no teeth?",
        "punchline": "A gummy bear!"
    }
]
Get Random Joke
  • URL: /api/jokes/random
  • Method: GET
  • Response: Single joke object
{
    "id": 1,
    "setup": "Why don't programmers like nature?",
    "punchline": "It has too many bugs!"
}
Get Joke by ID
  • URL: /api/jokes/<id>
  • Method: GET
  • URL Parameters: id=[integer]
  • Success Response:
{
    "id": 1,
    "setup": "Why don't programmers like nature?",
    "punchline": "It has too many bugs!"
}
  • Error Response (404 Not Found):
{
    "error": "Joke not found"
}
Health Check
  • URL: /health
  • Method: GET
  • Response:
{
    "status": "healthy"
}

Project Structure

joke_service/
├── app.py              # Main application file
├── requirements.txt    # Python dependencies
├── Dockerfile         # Docker configuration
├── .dockerignore     # Docker build exclusions
└── README.md         # Documentation

Docker Pull Command

docker pull clbo/joke-service