DjangoSQLiteAPIExample

πŸš€ Minimal Django API with SQLite

This project is a minimalist example of a Django API that allows access to an SQLite database. The API offers two access modes:

  • πŸ“‚ Unauthenticated Access: Some parts of the database are accessible without authentication.
  • πŸ”‘ Authenticated Access via Token: Some data requires authentication using a token.

🎯 Features

  • πŸ”„ REST API: Communication via RESTful endpoints.
  • πŸ”“ Public Access: Some data is accessible without authentication.
  • πŸ” Secure Access: Restricted data access via token authentication.
  • πŸ“ SQLite Database: Simple and efficient for data storage.

πŸ“‹ Prerequisites

  • Python: Version 3.8 or higher
  • Django: Version 4.x
  • Django REST Framework: For API management

πŸš€ Installation and Setup

πŸ› οΈ Installation

  1. Clone the repository:
    git clone https://github.com/mpek29/DjangoSQLiteAPIExample.git
    cd .\DjangoSQLiteAPIExample\
    
  2. Create a virtual environment:
    python -m venv env
    source env/bin/activate  # On Windows: env\Scriptsctivate
    
  3. Install dependencies:
    pip install -r requirements.txt
    
  4. Apply migrations:
    python manage.py migrate
    
  5. Start the server:
    python manage.py runserver
    

πŸ“‘ Using the API

πŸ“‚ Unauthenticated Access

Some routes are accessible without authentication:

curl http://127.0.0.1:8000/api/public/

πŸ”‘ Authenticated Access via Token

  1. Obtain an authentication token:
    curl -X POST http://127.0.0.1:8000/api/token/ -d "username=user&password=pass"
    

    This will return a token in the following format:

    { "token": "abc123xyz456" }
    
  2. Use the token to access protected routes:
    curl -H "Authorization: Token abc123xyz456" http://127.0.0.1:8000/api/protected/
    

πŸ“‚ Project Structure

β”œβ”€β”€ django_sqlite_api/
β”‚   β”œβ”€β”€ settings.py  # Django Configuration
β”‚   β”œβ”€β”€ urls.py  # API Routes
β”‚   β”œβ”€β”€ views.py  # REST Views
β”‚   β”œβ”€β”€ models.py  # Database Models
β”‚   β”œβ”€β”€ serializers.py  # Data Serialization
β”œβ”€β”€ db.sqlite3  # SQLite Database
β”œβ”€β”€ manage.py  # Django Management Command
└── requirements.txt  # Dependencies