The Chat Application is a real-time messaging system that allows users to communicate instantly through text messages using WebSockets.
python -m venv .venv.venv\Scripts\activatesource .venv/bin/activatepip install django djangorestframework mysqlclient
pip install django-filter
pip install djangorestframework-simplejwt # JWT Authentication
pip install channels # WebSocket support
pip install daphne # ASGI server for WebSocketdjango-admin startproject chatproject .
django-admin startapp chatappINSTALLED_APPS = [
...
'chatapp',
'rest_framework',
'rest_framework_simplejwt.token_blacklist',
'django_filters',
'channels',
]DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB_NAME',
'USER': 'DB_USER',
'PASSWORD': 'DB_PASSWORD',
'HOST': 'localhost', # Or your DB host
'PORT': '3306',
}
}python manage.py makemigrations
python manage.py migratepython manage.py runserver$env:DJANGO_SETTINGS_MODULE="chatproject.settings" # Windows PowerShell
daphne -p 8000 chatproject.asgi:application| Method | Endpoint | Description |
|---|---|---|
| POST | /api/register/ |
User Registration |
| POST | /api/login/ |
User Login |
| POST | /api/logout/ |
User Logout |
| GET | /api/profile/ |
Get Profile info |
| GET | /api/users/ |
Get User List |
| GET | /api/users/{id}/ |
Get User Profile info with Id |
| GET | /api/users/?name=demo |
Search Users |
| GET | /api/users/online/ |
Get Online Users Info |
| POST | /api/chat/start/ |
Start new Chat |
| GET | /api/chat/{chat_id}/messages/ |
All Messages |
| DELETE | /api/chat/{chat_id}/ |
Delete Chat |
| POST | /api/group/create/ |
Create Group |
| POST | /api/group/create/{group_id}/add-member/ |
Add Members in Group |
| POST | /api/group/create/{group_id}/remove-member/ |
Add Members from Group |
| GET | /api/group/create/{group_id}/messages/ |
Fetch Group Messages |
| DELETE | /api/group/create/{group_id}/ |
Delete Group |
{
"name": "demo",
"email": "demo@gmail.com",
"password": "demo@123",
"is_online": true
}{
"email": "demo@gmail.com",
"password": "demo@123"
}- Returns access and refresh tokens
Use access token in Authorization header for protected endpoints:
Authorization: Bearer <access_token>{
"refresh_token": "Your Refresh Token"
}
- Use access token in Authorization header for protected endpoints:
Authorization: Bearer <access_token>
- Use refresh token in payload for Logout{
"type": "personal"
}{
"name": "Demo Group"
}{
"user_id": 1
}ws://127.0.0.1:8000/ws/chat/{chat_id}/?user_id={id}
- Message
{
"event": "send_message",
"message": "Hello",
"type": "text"
}ws://127.0.0.1:8000/ws/homescreen/?user_id={id}- Shows user all chat (Home Screen)
- Shows who were added to the Group & Removed from the Group