This is a simple REST API for managing Jokes of the Day (JOTD) built using Python and FastAPI.
- 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/.
Assuming you have docker installed, run:
> ./scripts/build_run_local.sh
This will expose the API at http://localhost:8000
With the API running on port 8000, run the test script:
> ./scripts/test_jotd_api.sh
-
POST /jotd
: Create a new JOTDrequest 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 IDresponse
{ "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 dateresponse
{ "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 IDrequest 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 IDresponse
{ "message": "jotd deleted" }