Skip to content

MCDA-Spoken-Love/MCDA_API

Repository files navigation

MCDA_API

How to run

1. Install dependencies

pip install -r requirements.txt

2. Set up environment variables

Create a .env file in the project root and add your secrets and database config:

DB_NAME=your_db_name
DB_USER=your_db_user
DB_USER_PASSWORD=your_db_password
DB_HOST=localhost
DB_PORT=3306
USER_TOKEN=your_api_token

3. Start Redis (for WebSocket support)

Make sure Redis is installed. Start it with:

redis-server

4. Run Django migrations

python manage.py migrate

5. Start the development server

python manage.py runserver

6. Start Daphne for WebSocket support

Activate your virtual environment and run:

source venv/bin/activate
uvicorn mcda_api_project.asgi:application --reload

7. Run tests

pytest

8. WebSocket testing

You can use test_ws.py to test WebSocket connections. Make sure your .env file contains a valid USER_TOKEN.

python test_ws.py

9. Create a user token for WebSocket/API authentication

To create a token for a user, run the following in the Django shell:

python manage.py shell

Then, in the shell:

from django.contrib.auth import get_user_model
from rest_framework.authtoken.models import Token
User = get_user_model()
user = User.objects.get(username="your_username")  # Replace with your username
token, created = Token.objects.get_or_create(user=user)
print(token.key)

Copy the token and use it in your .env or client code for authenticated WebSocket/API requests.

Note:

  • For production, configure your database, secrets, and allowed hosts securely.
  • Redis is required for Django Channels group messaging and multi-process support.
  • Daphne is required for WebSocket support.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages