Implementation of long-polling in asynchronous web framework like twisted or klein

720 Views Asked by At

I'm relatively new to REST API and web development in general. I'm looking for options for a client GET request to receive data incrementally/streaming until all data is sent with some criterias:

  • Has to be async (need to use twisted/klein as framework), here's only with Flask as reference.
  • Need to render server-side (next.js has option with socket.io in here with react -> which is the frontend I use), I know it's unrelated, but it's nice to have reading materials like that so I can glue/frankensteinize components together.

my model

From the server (python) It has to be yielded from generator object, right? what confusing me is the underlying options/quirks between websocket, long polling, and server-sent-events, not to mention frameworks like autobahn, WAMP and service like pushpin and crossbar.io which I think is overkill for my case.

The reason I'm mentioning them all is to ask for best practice in using them with their many ways of implementation (phew..). It's a bit overwhelming without enough experience.

At the core level (http headers/protocols/curl), what need to be actually set on the client and server given my scenario? And does long polling sounds like the solution? Does async is a good idea?

Reference reading:

What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?

My Understanding of HTTP Polling, Long Polling, HTTP Streaming and WebSockets

http://blog.fanout.io/2016/11/21/moving-from-polling-to-long-polling/

https://blog.al4.co.nz/2016/01/streaming-json-with-flask/

TL;DR: Best practice of long polling implementation in asynchronous python webserver.

0

There are 0 best solutions below