Skip to content

ZakariaElkhadir/Django-ToDo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django ToDo API

A RESTful API for managing ToDo tasks using Django and Django REST Framework (DRF).

Features

  • CRUD operations for ToDo tasks
  • RESTful endpoints with Django REST Framework
  • CORS headers enabled for cross-origin requests
  • Browsable API interface
  • Filtering support (optional enhancement)

Requirements

  • Python 3.9+
  • Pipenv (for virtual environment management)
  • Django
  • Django REST Framework
  • Django CORS Headers

Installation

  1. Clone the repository

    git clone https://github.com/ZakariaElkhadir/Django-ToDo.git
    cd Django-ToDo
  2. Set up virtual environment and install dependencies

    pipenv install
    pipenv shell
  3. Run migrations

    python manage.py migrate
  4. Create a superuser (optional)

    python manage.py createsuperuser
  5. Run the development server

    python manage.py runserver

API Endpoints

Method Endpoint Description
GET /api/todos/ List all todos
POST /api/todos/ Create a new todo
GET /api/todos/{id}/ Retrieve a specific todo
PUT /api/todos/{id}/ Update a specific todo
PATCH /api/todos/{id}/ Partially update a specific todo
DELETE /api/todos/{id}/ Delete a specific todo

Testing with Postman

1. Import the Collection

  • Download the Postman Collection (optional).
  • Import it into Postman using File > Import.

2. Manual Testing

Base URL: http://localhost:8000/api/todos/

Create a Todo (POST)

  • Set request method: POST
  • Set headers:
    Content-Type: application/json
    
  • Request body (raw JSON):
    {
      "title": "Buy groceries",
      "description": "Milk, eggs, bread",
      "completed": false
    }

List All Todos (GET)

  • Set request method: GET
  • Send request to: http://localhost:8000/api/todos/

Update a Todo (PUT)

  • Set request method: PUT
  • Use URL format: http://localhost:8000/api/todos/1/ (replace 1 with actual ID)
  • Request body:
    {
      "title": "Updated title",
      "completed": true
    }

Delete a Todo (DELETE)

  • Set request method: DELETE
  • Use URL format: http://localhost:8000/api/todos/1/

3. Using cURL

Create a Todo:

curl -X POST -H "Content-Type: application/json" -d '{"title":"New Task"}' http://localhost:8000/api/todos/

List All Todos:

curl http://localhost:8000/api/todos/

Update a Todo:

curl -X PUT -H "Content-Type: application/json" -d '{"title":"Updated Task"}' http://localhost:8000/api/todos/1/

Browsable API

Access the API through your web browser at:

http://localhost:8000/api/todos/

Optional Enhancements

Add Filtering:

# settings.py
REST_FRAMEWORK = {
    'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
}
  • Filter using: /api/todos/?completed=true

Add Pagination:

# settings.py
REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 10
}

Add JWT Authentication

Use djangorestframework-simplejwt for secure authentication.

About

practicing ToDo list backend using Django

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages