GET/hello_world
WebSockets
To handle real-time communication, Batman learned how to work with WebSockets. He created a WebSocket class and wrapped it around his Robyn app:
Request
GET
/hello_worldfrom robyn import Robyn, jsonify, WS
app = Robyn(__file__)
websocket = WS(app, "/web_socket")
@websocket.on("message")
def connect():
return "Hello world, from ws"
@websocket.on("close")
def close():
return "Goodbye world, from ws"
@websocket.on("connect")
def message():
return "Connected to ws"
For an asynchronous request, Batman used:
Request
GET
/hello_world@app.get("/")
async def h(request):
return "Hello, world"
What's next?
As the codebase grew, Batman wanted to onboard the justice league to help him manage the application.
Robyn told him about the different ways he could scale his application, and how to use views and subrouters to make his code more readable.