Reputation: 15602
I am trying to use PubNub to set up a system for pushing simple real time messages from my web server to clients. I am running Django on Heroku.
In particular, I'm interested how to establish a channel between the server and the client, which this requires sharing a unique channel id between the two.
Our website is a type of social networking site -- lots of users will be logged in at once. We just want a way to update their interface when they get something like a new message or friend request, without requiring a refresh.
I have an idea of what to do, but I thought there might be some best practices I'm not aware of, so I wanted to get some feedback.
Technically, I am worried this violates REST principles. The single call to the API end point functions both to create data server side, like a POST, and return data to the client, like a GET.
I'd appreciate any thoughts on relevant best practices. Thanks!
Upvotes: 4
Views: 1467
Reputation: 33824
It sounds like you'd benefit from using Pusher. They are more or less the defacto hosted websockets provider that lets you have clients subscribe (through their browser with sockets) to Pusher, listening on various channels. You then send simple API calls to Pusher, which broadcasts it to all the connected clients.
This is the best way to handle realtime updates to many clients logged in at once, without doing polling via AJAX, or rolling your own websockets stuff.
I highly recommend giving pusher a look. (As a note, their free tier is extremely generous.)
Upvotes: 4