Skip to content

Latest commit

 

History

History
93 lines (75 loc) · 2.43 KB

README.md

File metadata and controls

93 lines (75 loc) · 2.43 KB

Pyjokes API

Pyjokes Logo

This is a simple Flask application that provides a random joke through an API using the Pyjokes library. The application includes routes for documentation and fetching a joke, with proper error handling.

Features

  • Redirects:
    • / redirects to /docs/.
    • /joke/ redirects to /joke.
  • Documentation:
    • /docs and /docs/ provide information about the available routes.
  • Random Joke:
    • /joke returns a random joke in JSON format using the pyjokes library. It accepts an optional lang parameter to specify the language of the joke.

Requirements

  • Python 3.x
  • Flask
  • pyjokes

Installation

  1. Clone the repository:

    git clone https://github.com/Ahmedallion/pyjokes-api.git
    cd pyjokes-api
  2. Create a virtual environment and activate it:

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  3. Install the required packages:

    pip install flask pyjokes

Running the Application

  1. Start the Flask server:

    python app.py
  2. Access the application:

    • Open a web browser and navigate to http://127.0.0.1:5000/.

API Endpoints

  • Root: /
    • Redirects to the documentation page.
  • Documentation: /docs or /docs/
    • Provides information about the available routes.
  • Joke: /joke
    • Returns a random joke in JSON format. Accepts an optional lang parameter to specify the language of the joke.
  • Joke Redirect: /joke/
    • Redirects to /joke.

Example Responses

  • Documentation (GET /docs):

    {
        "routes": {
            "/": {
                "description": "Redirects to the docs page."
            },
            "/docs": {
                "description": "Shows the routes for this API."
            },
            "/joke": {
                "description": "Tells a random joke.",
                "parameters": {
                    "lang": {
                        "description": "Specifies the language of the joke.",
                        "valid_options": "'en', 'de', 'es', 'gl', 'eu'', 'it'"
                    }
                }
            }
        }
    }
  • Random Joke (GET /joke):

    {
        "joke": "Ubuntu users are apt to get this joke."
    }