The API allows users to create and manage todo lists, create and update todo items, mark items as completed, delete items from a list, delete the entire list, and edit both items and lists.
These instructions will guide you on how to set up and use the Todo List REST API on your local machine.
To run the API, you'll need the following installed on your machine:
-
Python 3.11
-
pipenv
-
postgresql
-
redis
-
celery
-
Postman / Insomnia for testing the api.
-
Optionally Docker (requires docker compose and gmake)
-
install docker if not available locally
-
create a
.env.dockerfile locally and add details usingenv_docker_sample.txt -
install make
apt update && apt install -y make -
clone the repository
git clone git@github.com:armstrongsouljah/task-manager-api.git- cd task-manager-api
- docker compose up
- open a separate terminal and run the following commands
make migrate
This command runs migrations make superuser
this creates a superuser that will allow you access the admin interface- try out the api by heading over to postman by the helpof the provided collection button.
-
Clone the repository:
git clone git@github.com:armstrongsouljah/task-manager-api.git
- Navigate to the project directory:
cd todo-list-api - Activate a virtual environment & install dependencies
mkdir .venv && pipenv shell; pipenv install;
- Set up the environment variables:
Create a .env file in the root directory of the project.
DEBUG=True
SECRET_KEY='secret for the django project'
DATABASE_URL=The connection URI for your postgres database.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'your-email'
EMAIL_HOST_PASSWORD = 'your-app-password' `set up an app password for your gmail`
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL='your-email'
CELERY_BROKER_URL = "redis://localhost:6379"
CELERY_RESULT_BACKEND = "redis://localhost:6379"
ALLOWED_HOSTS=.localhost,localhost
- Start the server
./manage.py runserver
The API should now be running on http://localhost:8000/4.1. Start the celery worker in a separate terminal
python -m celery -A todolist worker -l info
Celery should now be able to offload heavy tasks.- Stop the server with
Ctrl+Cand Create a test admin user
./manage.py createsuperuser
- Restart the server and log into the admin interface
http://localhost:8000/admin
URL: /auth/users/register
Method: POST
Request Body:
email: User's email address.
password: User's password.
Response:
email: The registered user's email.
token: An authentication token.
URL: auth/users/login/user/
Method: POST
Request Body:
email: User's email address.
password: User's password.
Response:
msg: Success message.
token: An authentication token.
Create a Todo List
URL: /todos/lists/new-list/
Method: POST
Request Headers:
Authorization: Bearer token obtained during authentication.
Request Body:
title: Name of the todo list.
Response:
list: The created todo list object.
URL: /todos/lists/
Method: GET
Request Headers:
Authorization: Bearer token obtained during authentication.
Response:
lists: An array of todo list objects.
URL: /todos/lists/update/?short_code=shortcode
Method: PATCH
Request Headers:
Authorization: Bearer token obtained during authentication.
Response:
msg: Success or failure of updating a tod list.
Update a Todo List
URL: /lists/:id
Method: PUT
Request Headers:
Authorization: Bearer token obtained during authentication.
Request Body:
name: Updated name of the todo list.
Response:
list: The updated todo list object.
URL: /todos/lists/delete-list/?pk=list_id
Method: DELETE
Request Headers:
Authorization: Bearer token obtained during authentication.
**Response:
Create a Todo List
URL: /todos/items/new-item/
Method: POST
Request Headers:
Authorization: Bearer token obtained during authentication.
Request Body:
name: Name of the tod item.
todo_list: pk of the list it should belong to
Response:
object: The created todo item object
URL: /todos/items/
Method: GET
Request Headers:
Authorization: Bearer token obtained during authentication.
Response:
lists: An array of todo item objects.
URL: /todos/items/complete/?pk=1
Method: PATCH
Request Headers:
Authorization: Bearer token obtained during authentication.
RequestBody:
is_completed: true or false "to mark on unmark an item"
Response:
msg: Success or failure of updating a tod list.
Mark Entire Todo list completed
URL: /todos/lists/update/?short_code=D1IJZ7vA
Method: PUT
Request Headers:
Authorization: Bearer token obtained during authentication.
Request Body:
is_completed: Boolean to mark completed
QueryParams:
short_code: unique identifier for list.
Response:
dict: Success or failure message.
URL: /todos/items/delete-item/?pk=5&todo_list=2
Method: DELETE
Request Headers:
Authorization: Bearer token obtained during authentication.
QueryParams:
pk: id of todo item
todo_list: pk of the list from which you're removing the item.
**Response: