From 9144f0158aedf3ac825dcd6ae8a6087450a07b18 Mon Sep 17 00:00:00 2001 From: Taoufik Date: Tue, 25 Dec 2018 01:15:54 +0000 Subject: [PATCH 1/3] Websocket docs --- docs/source/tour.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/source/tour.rst b/docs/source/tour.rst index a331d7d..c50c1c7 100644 --- a/docs/source/tour.rst +++ b/docs/source/tour.rst @@ -184,6 +184,19 @@ If you'd like a view to be executed before every request, simply do the followin Now all requests to your HTTP Service will include an ``X-Pizza`` header. +WebSocket Support +----------------- + +Responder supports WebSockets:: + + @api.route('/ws', websocket=True) + async def ws1(ws): + await ws.accept() + while True: + name = await ws.receive_text() + await ws.send_text(f"Hello {name}!") + await ws.close() + Using Requests Test Client -------------------------- From c8627939de729fec72ba988b58a85630514ffcdb Mon Sep 17 00:00:00 2001 From: Taoufik Date: Tue, 25 Dec 2018 01:18:44 +0000 Subject: [PATCH 2/3] Update --- docs/source/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/index.rst b/docs/source/index.rst index bee505c..e43f69b 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -47,6 +47,7 @@ Features - A pleasant API, with a single import statement. - Class-based views without inheritance. - ASGI framework, the future of Python web services. +- WebSocket support! - The ability to mount any ASGI / WSGI app at a subroute. - *f-string syntax* route declaration. - Mutable response object, passed into each view. No need to return anything. From 60b0c5f25605a1c9a528dd44135b3942de1c971b Mon Sep 17 00:00:00 2001 From: Taoufik Date: Tue, 25 Dec 2018 01:32:38 +0000 Subject: [PATCH 3/3] Update --- docs/source/tour.rst | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/source/tour.rst b/docs/source/tour.rst index c50c1c7..994b23e 100644 --- a/docs/source/tour.rst +++ b/docs/source/tour.rst @@ -190,13 +190,28 @@ WebSocket Support Responder supports WebSockets:: @api.route('/ws', websocket=True) - async def ws1(ws): + async def websocket(ws): await ws.accept() while True: name = await ws.receive_text() await ws.send_text(f"Hello {name}!") await ws.close() +Accepting the connection:: + + await websocket.accept() + +Sending and receiving data:: + + await websocket.send_{format}(data) + await websocket.receive_{format}(data) + +Supported formats: ``text``, ``json``, ``bytes``. + +Closing the connection:: + + await websocket.close() + Using Requests Test Client --------------------------