REST API for simple TODO application built onto django-rest-framework
The application requires:
- docker (tested on version 27.3.1)
- docker-compose (tested on version 2.29.7)
To create and run containers with postgres and django you can run:
docker-compose up
It will create two containers. First with postgres database and second with django server on gunicorn. Database data is stored on a docker volume, therefore it is persistent.
Django server will be available on port 8001.
curl http://localhost:8001/todo/api/v1/tasks
If you want to run django server without docker and with sqlite database, you need to setup environment like this:
python3.11 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver 8001
Example: http://localhost:8001/todo/api/v1/tasks
Response body:
[
{
"id" : 1,
"title" : "title",
"description" : "desc",
"done" : true
},
{
"id" : 2,
"title" : "title2",
"description" : "desc2",
"done" : false
}
]
Example: http://localhost:8001/todo/api/v1/tasks/[id]
Response body:
{
"id" : 3,
"done" : false,
"description" : "desc",
"title" : "title"
}
Example: Create – POST http://localhost:8001/todo/api/v1/tasks
Request body:
{
"title" : "title",
"description" : "desc",
"done" : false,
}
Example: Update - PUT http://localhost:8001/todo/api/v1/tasks/[id]
Request body:
{
"title" : "title",
"description" : "desc",
"done" : false,
}
Example: Delete - DELETE http://localhost:8001/todo/api/v1/tasks/[id]
You may want to test the API from a command line. Here are some curl examples to execute by yourself:
curl -X POST -H 'Content-type: application/json' \
-d '{"title": "t", "description": "d", "done": true}' \
http://localhost:8001/todo/api/v1/tasks
curl http://localhost:8001/todo/api/v1/tasks
curl -X PUT \
-H 'Content-type: application/json' \
-d '{"title": "changed title", "description": "desc", "done": false}' \
http://localhost:8001/todo/api/v1/tasks/3
curl http://localhost:8001/todo/api/v1/tasks/1
curl -X DELETE http://localhost:8001/todo/api/v1/tasks/1