The Wayback Machine - https://web.archive.org/web/20211219062921/https://github.com/pennlabs/django-rest-live
Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Django REST Live

Documentation CircleCI Coverage Status PyPi Package

django-rest-live adds real-time subscriptions over websockets to Django REST Framework views by leveraging websocket support provided by Django Channels.

The goal of this project is to be as close to a drop-in realtime solution as possible for projects already using Django REST Framework.

After running pip install django-rest-live, The only change to your existing code is to add a mixin to the REST Framework view that you want to make realtime-capable:

from rest_framework.viewsets import ModelViewSet
from rest_live.mixins import RealtimeMixin

class TaskViewSet(ModelViewSet, RealtimeMixin): # The only change is adding the RealtimeMixin!
    queryset = Task.objects.all()
    serializer_class = TaskSerializer

There's a few more lines needed to set up routing with Django Channels, so you should check out the full tutorial and reference documentation!

django-rest-live took initial inspiration from this article by Kit La Touche. Differently from projects like djangochannelsrestframework, django-rest-live does not aim to supplant REST Framework for performing CRUD actions through a REST API. Instead, it is designed to be used in conjunction with HTTP REST endpoints. Clients should still use normal REST framework endpoints generated by ViewSets and other API views to get initial data to populate a page, as well as any write-driven behavior (POST, PATCH, PUT, DELETE). django-rest-live gets rid of the need for periodic polling GET requests to for resource updates after page load.