Skip to content

ADCarthan88/Secure-Backend-API-Development

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Secure Backend API Development

Django Django REST Framework JWT Python SQLite

πŸš€ Enterprise-grade REST API with bulletproof security

A production-ready backend API featuring JWT authentication, comprehensive input validation, and advanced security measures built with Django REST Framework.


🎯 What This App Does

This secure backend API provides a robust foundation for modern web applications, offering:

  • πŸ” Secure User Authentication - JWT-based auth system with refresh tokens
  • πŸ‘€ User Management - Complete user registration, login, and profile management
  • πŸ“ Content Management - CRUD operations for user-generated content (posts)
  • πŸ›‘οΈ Enterprise Security - Multiple layers of protection against common vulnerabilities
  • ⚑ High Performance - Optimized for scalability and speed
  • πŸ“Š API Documentation - Well-documented endpoints for easy integration

✨ Key Features

πŸ”’ Security First

  • JWT Authentication with access & refresh tokens
  • Strong Password Policy (8+ chars, mixed case, numbers, symbols)
  • Rate Limiting to prevent brute force attacks
  • CORS Protection with configurable origins
  • XSS & CSRF Protection via security headers
  • SQL Injection Prevention through Django ORM
  • Secure Password Hashing with Django's built-in system

πŸš€ Developer Experience

  • RESTful API Design following industry standards
  • Comprehensive Input Validation with detailed error messages
  • Automated Testing with included test suite
  • Environment Configuration for different deployment stages
  • Clean Code Architecture with separation of concerns
  • Detailed Documentation with usage examples

πŸ“± User Features

  • User registration with email validation
  • Secure login/logout functionality
  • Profile management and updates
  • Password change with validation
  • Personal content creation and management
  • Token refresh for seamless sessions

πŸ› οΈ Tech Stack

Backend Framework

  • Django 4.2.7 - High-level Python web framework
  • Django REST Framework 3.14.0 - Powerful toolkit for building APIs
  • Django CORS Headers - Cross-Origin Resource Sharing support

Authentication & Security

  • djangorestframework-simplejwt 5.3.0 - JWT authentication
  • python-decouple 3.8 - Environment variable management
  • cryptography 41.0.7 - Cryptographic recipes and primitives

Database

  • SQLite (Development) - Lightweight database
  • PostgreSQL (Production Ready) - Enterprise database support

Additional Tools

  • Rate Limiting - Built-in throttling mechanisms
  • Input Validation - Custom validators for data integrity
  • Security Headers - XSS, CSRF, and content type protection

πŸ“Έ API Screenshots

πŸ” Authentication Flow

// POST /api/auth/register/
{
  "username": "johndoe",
  "email": "john@example.com",
  "password": "SecurePass123!",
  "password_confirm": "SecurePass123!"
}

// Response
{
  "message": "User registered successfully",
  "user_id": 1,
  "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
  "refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
}

πŸ‘€ User Profile Management

// GET /api/auth/profile/
{
  "id": 1,
  "username": "johndoe",
  "email": "john@example.com",
  "date_joined": "2024-01-15T10:30:00Z",
  "is_active": true
}

πŸ“ Content Creation

// POST /api/users/posts/
{
  "title": "My First Secure Post",
  "content": "This post was created using the secure API!"
}

// Response
{
  "id": 1,
  "title": "My First Secure Post",
  "content": "This post was created using the secure API!",
  "author": "johndoe",
  "created_at": "2024-01-15T10:35:00Z",
  "is_published": true
}

🌐 Live Demo

πŸš€ Quick Test Drive

  1. Clone and Run Locally:
git clone https://github.com/ADCarthan88/Secure-Backend-API-Development.git
cd Secure-Backend-API-Development
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver
  1. Test the API:
python test_api.py
  1. Interactive API Testing:
    • Visit http://localhost:8000/admin/ for Django admin
    • Use tools like Postman or curl to test endpoints
    • Check the test_api.py file for example requests

πŸ“‹ API Endpoints Overview

Method Endpoint Description Auth Required
POST /api/auth/register/ User registration ❌
POST /api/auth/login/ User login ❌
POST /api/auth/logout/ User logout βœ…
GET /api/auth/profile/ Get user profile βœ…
POST /api/auth/change-password/ Change password βœ…
POST /api/auth/token/refresh/ Refresh JWT token ❌
GET/PUT /api/users/profile/ Manage user profile βœ…
GET/POST /api/users/posts/ List/Create posts βœ…
GET/PUT/DELETE /api/users/posts/<id>/ Manage specific post βœ…
GET /api/users/my-posts/ Get user's posts βœ…

πŸš€ Quick Start Guide

1️⃣ Installation

# Clone the repository
git clone https://github.com/ADCarthan88/Secure-Backend-API-Development.git
cd Secure-Backend-API-Development

# Install dependencies
pip install -r requirements.txt

2️⃣ Database Setup

# Run migrations
python manage.py makemigrations
python manage.py migrate

# Create superuser (optional)
python manage.py createsuperuser

3️⃣ Start Development Server

python manage.py runserver

4️⃣ Test the API

# Run automated tests
python test_api.py

# Or test manually with curl
curl -X POST http://localhost:8000/api/auth/register/ \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "email": "test@example.com",
    "password": "SecurePass123!",
    "password_confirm": "SecurePass123!"
  }'

πŸ”§ Configuration

Environment Variables

Create a .env file in the project root:

SECRET_KEY=your-super-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
DB_NAME=secure_api_db
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=localhost
DB_PORT=5432

Production Deployment Checklist

  • Set DEBUG=False
  • Configure PostgreSQL database
  • Set strong SECRET_KEY
  • Configure HTTPS
  • Update ALLOWED_HOSTS
  • Set proper CORS origins
  • Configure static files serving
  • Set up monitoring and logging

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❀️ using Django REST Framework

⭐ Star this repo if you found it helpful!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages