A simple Blog Application API built with Django REST Framework, featuring JWT authentication, blog posts, comments, and likes functionality.
Live Server: https://blog-interview.sydeestack.com/
API Documentation: https://blog-interview.sydeestack.com/api/docs/
The default page displays the Swagger documentation interface.
- Backend: Django 5.2.6, Django REST Framework 3.16.1
- Database: MySQL
- Authentication: JWT (djangorestframework-simplejwt)
- API Documentation: drf-spectacular (OpenAPI/Swagger)
- Image Upload: Pillow
- Environment Management: python-decouple
- Production Server: Gunicorn
- Containerization: Docker
- Deployment: Railway (with Git webhooks)
- User signup and login with email
- JWT token-based authentication
- Password reset with OTP via email
- Email-based user management
- Create, read, update, delete blog posts
- Image upload for cover photos
- Like/unlike posts
- View users who liked a post
- Pagination support
- Create, update, delete comments on posts
- Like/unlike comments
- View users who liked a comment
- Comment validation and moderation
- RESTful API design
- Comprehensive API documentation (Swagger/OpenAPI)
- API versioning support
- CORS configuration
- Input validation and error handling
- Production-ready Docker setup
- Python 3.11+
- MySQL database
- Docker (optional)
- SMTP credentials for email functionality
-
Clone the repository
git clone <git_url> cd django-rest-blog-api
-
Create and activate virtual environment
# Windows python -m venv venv venv\Scripts\activate # macOS/Linux python -m venv venv source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Environment setup
cp .env.example .env
Fill in the required environment variables in
.env:SECRET_KEY=your-secret-key DEBUG=True DB_NAME=your-database-name DB_USER=your-database-user DB_PASSWORD=your-database-password DB_HOST=localhost DB_PORT=3306 EMAIL_HOST=smtp.gmail.com EMAIL_PORT=587 EMAIL_HOST_USER=[email protected] EMAIL_HOST_PASSWORD=your-app-password DEFAULT_FROM_EMAIL=[email protected] ALLOWED_HOSTS=localhost,127.0.0.1
-
Run migrations
python manage.py migrate
-
Start development server
python manage.py runserver
The API will be available at
http://localhost:8000/
-
Ensure Docker is installed
-
Build the Docker image
docker build -t blog-api . -
Create environment file
cp .env.example .env
Fill in your database and SMTP credentials in
.env -
Run the container
docker run -d -p 8000:80 --env-file .env blog-api
-
Access the application
- API:
http://localhost:8000/ - Swagger Docs:
http://localhost:8000/api/docs/
- API:
POST /api/v1/auth/signup/- User registrationPOST /api/v1/auth/login/- User loginPOST /api/v1/auth/token/refresh/- Refresh JWT tokenPOST /api/v1/auth/password-reset/- Request password reset OTPPOST /api/v1/auth/password-confirm/- Confirm password reset
GET /api/v1/posts/- List all posts (paginated)POST /api/v1/posts/- Create a new postGET /api/v1/posts/{id}/- Get post detailsPUT /api/v1/posts/{id}/- Update postDELETE /api/v1/posts/{id}/- Delete postPOST /api/v1/posts/{id}/like/- Like/unlike postGET /api/v1/posts/{id}/likes/- Get post likes
GET /api/v1/comments/- List comments (with post filter)POST /api/v1/comments/- Create a new commentPUT /api/v1/comments/{id}/- Update commentDELETE /api/v1/comments/{id}/- Delete commentPOST /api/v1/comments/{id}/like/- Like/unlike commentGET /api/v1/comments/{id}/likes/- Get comment likes
| Variable | Description | Required | Default |
|---|---|---|---|
SECRET_KEY |
Django secret key | Yes | - |
DEBUG |
Debug mode | No | True |
DB_NAME |
MySQL database name | Yes | - |
DB_USER |
MySQL username | Yes | - |
DB_PASSWORD |
MySQL password | Yes | - |
DB_HOST |
MySQL host | No | localhost |
DB_PORT |
MySQL port | No | 3306 |
EMAIL_HOST |
SMTP host | No | smtp.gmail.com |
EMAIL_PORT |
SMTP port | No | 587 |
EMAIL_HOST_USER |
SMTP username | Yes | - |
EMAIL_HOST_PASSWORD |
SMTP password | Yes | - |
DEFAULT_FROM_EMAIL |
From email address | No | [email protected] |
ALLOWED_HOSTS |
Comma-separated allowed hosts | No | localhost,127.0.0.1 |
API_VERSION |
API version | No | v1 |
OTP_EXPIRY_MINUTES |
OTP expiry time | No | 10 |
django-rest-blog-api/
├── authentication/ # User authentication app
│ ├── models.py # Custom User model, PasswordResetOTP
│ ├── serializers.py # Auth serializers
│ ├── views.py # Auth API views
│ ├── urls.py # Auth URL patterns
│ ├── backends.py # Email authentication backend
│ └── utils.py # Email utilities
├── posts/ # Blog posts app
│ ├── models.py # Post model
│ ├── serializers.py # Post serializers
│ ├── views.py # Post API views
│ └── urls.py # Post URL patterns
├── comments/ # Comments app
│ ├── models.py # Comment model
│ ├── serializers.py # Comment serializers
│ ├── views.py # Comment API views
│ └── urls.py # Comment URL patterns
├── blog/ # Main project
│ ├── settings.py # Django settings
│ ├── urls.py # Main URL configuration
│ └── wsgi.py # WSGI configuration
├── media/ # Uploaded files
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose setup
├── start.sh # Production startup script
└── .env.example # Environment variables template
The application is deployed on Railway with automatic deployment via Git webhooks:
- Push to main branch triggers automatic deployment
- Environment variables are configured in Railway dashboard
- Database is hosted on Railway MySQL
- Static files are served by Gunicorn
- Health checks monitor application status
The API includes comprehensive validation and error handling:
- Input validation on all endpoints
- Proper HTTP status codes
- Detailed error messages
- JWT token validation
- Permission-based access control
- JWT Authentication: Secure token-based authentication
- Email-based Login: Users login with email instead of username
- Password Reset: OTP-based password reset via email
- Image Upload: Support for post cover photos
- Like System: Like/unlike posts and comments
- Pagination: Efficient data loading with pagination
- API Documentation: Interactive Swagger/OpenAPI documentation
- CORS Support: Cross-origin resource sharing configuration
- Production Ready: Docker containerization with Gunicorn
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is part of a technical interview assessment.
Live Demo: https://blog-interview.sydeestack.com/
API Documentation: https://blog-interview.sydeestack.com/api/docs/