Installation

Dependencies

Set Up

If you haven't installed and properly configured Django Channels, then make sure to do that before continuing on with Django REST Live.

  1. Add rest_live to your INSTALLED_APPS.
INSTALLED_APPS = [
    # Any other django apps
    "rest_framework",
    "channels",
    "rest_live",
]
  1. Create a RealtimeRouter in your ASGI routing file and add router.consumer to the websocket routing you set up with Django Channels. Feel free to choose any URL path, here we've chosen /ws/subscribe/.
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.urls import path
from django.core.asgi import get_asgi_application
from rest_live.routers import RealtimeRouter

router = RealtimeRouter()

application = ProtocolTypeRouter({
    "http": get_asgi_application(),
    "websocket": AuthMiddlewareStack(
    URLRouter([
        path("ws/subscribe/", router.as_consumer().as_asgi(), name="subscriptions"),
    ])
),
})

Note: if using Channels version 2, omit the as_asgi() method.

That's it! You're now ready to configure and use django-rest-live.