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
- Clone the repository:
git clone https://github.com/mpek29/DjangoSQLiteAPIExample.git cd .\DjangoSQLiteAPIExample\ - Create a virtual environment:
python -m venv env source env/bin/activate # On Windows: env\Scriptsctivate - Install dependencies:
pip install -r requirements.txt - Apply migrations:
python manage.py migrate - 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
- 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" } - 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