Shahzad Akram
Shahzad Akram

Reputation: 5274

Django realtime access on mobile devices

I am new to web backend. Currently I am using DjangoREST framework, it is working upon my expectations except it doesn't assist in real-time communication. I don't want to use firebase. In other words I wanna build my own backend like firebase not all features but at least real-time access on mobile devices. Recently I found Django Channels , as I have mentioned I haven't background of server-side developing so I don't know much about this.

I just wanna ask is Django realtime access is possible on mobile devices through Django Channels ? Can I do something similer to DjangoREST GET, PUT, POST and DELETE in Django Channels ?

Upvotes: 2

Views: 907

Answers (1)

Reza Torkaman Ahmadi
Reza Torkaman Ahmadi

Reputation: 3058

If you want to do it with django, then you don't have much of choices. And in my opinion django-channels is the best solution for that. django-channels is for handling web-scoket, chat and real-time connections:

Django Channels is a project that takes Django and extends its abilities beyond HTTP - to handle WebSockets, chat protocols, IoT protocols, and more. It’s built on a Python specification called ASGI.

Your API design will not be that different. Of course you have to use other tools and you will not have some of options that django-rest-framework gives you. But it's a good library and will handle your situation.

And about your Question, YES, it's possible to handle it every where that you want. almost all browser support websocket and almost all mobile programming languages support web socket by design. (read more about communication methods in current applications in this link: web-api-design-methods

Of course you will loose some of features in django rest like serialziers and you will have different routers and ... Also you just need to send your data through messages using websocket and no need for http methods. Cause it's anther protocol (you can notice it by ws:// in front of it's api calls)

But remember you will have some challenges in django-channels like:

  • You need an asgi web server to handle your requests to django server like daphne which is different and you should learn how to config it.

  • You don't have serializer and stuff like that and you should validate your inputs (by the way, there is a library channels-api for django which provide functionality like django-rest, I didn't test it but you can check it and see how it goes.)

  • Your server performance will depend on ram for web socket communications. because each socket that opens will consume memory and increasing number of users will cause performance problems. Also be noted that django-channels can't handle range like 1M requests and you should consider other protocols like mqtt that are lighter by design if your project is in that scale.

Upvotes: 5

Related Questions