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. diff --git a/docs/source/tour.rst b/docs/source/tour.rst index a331d7d..994b23e 100644 --- a/docs/source/tour.rst +++ b/docs/source/tour.rst @@ -184,6 +184,34 @@ 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 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 --------------------------