Skip to content

Interview REST API; I made extensive use of Chat GPT and GitHub CoPilot to generate much of the scaffolding

Notifications You must be signed in to change notification settings

BadAsstronaut/jotd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Joke of the Day (JOTD) REST API

This is a simple REST API for managing Jokes of the Day (JOTD) built using Python and FastAPI.

Getting Started

Local development

Prerequisites

  • python3.8 or later

For local development, create and activate a virtual environment using:

> python -m venv .venv
> source .venv/bin/activate

Install the dependencies:

(.venv) > pip install -r requirements.txt

Run the development server:

(.venv) > cd src
(.venv) > uvicorn main:app --reload

The API will be available at http://localhost:8000/.

Run with Docker

Assuming you have docker installed, run:

> ./scripts/build_run_local.sh

This will expose the API at http://localhost:8000

Testing

With the API running on port 8000, run the test script:

> ./scripts/test_jotd_api.sh

Endpoints

  • POST /jotd: Create a new JOTD

    request body

    {
        "text": "Why did the tomato turn red? Because it saw the salad dressing!",
        "date": "2022-01-01",
        "description": "A pun about salad"
    }

    response

    {
            "jotd": {
            "id": 1,
            "text": "Why did the tomato turn red? Because it saw the salad dressing!",
            "date": "2022-01-01",
            "description": "A pun about salad"
        }
    }
  • GET /jotd/{id}: Retrieve a specific JOTD by ID

    response

    {
            "jotd": {
            "id": 1,
            "text": "Why did the tomato turn red? Because it saw the salad dressing!",
            "date": "2022-01-01",
            "description": "A pun about salad"
        }
    }
  • GET /jotd/date/{date}: Retrieve a specific JOTD by date

    response

    {
            "jotd": {
            "id": 1,
            "text": "Why did the tomato turn red? Because it saw the salad dressing!",
            "date": "2022-01-01",
            "description": "A pun about salad"
        }
    }
  • PUT /jotd/{id}: Update a specific JOTD by ID

    request body

    {
        "text": "Why did the tomato turn red? Because it saw the salad dressing!",
        "date": "2022-01-01",
        "description": "A pun about salad"
    }

    response

    {
            "jotd": {
            "id": 1,
            "text": "Why did the tomato turn red? Because it saw the salad dressing!",
            "date": "2022-01-01",
            "description": "A pun about salad"
        }
    }
  • DELETE /jotd/{id}: Delete a specific JOTD by ID

    response

    {
        "message": "jotd deleted"
    }

Dependencies

Dev Dependencies

About

Interview REST API; I made extensive use of Chat GPT and GitHub CoPilot to generate much of the scaffolding

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published