WebSocket

say it: “WEB-sok-it” /ˈwɛbˌsɑkɪt/

A connection that stays open for two-way messages, such as chat.

What is WebSocket?

A WebSocket is a two-way connection that stays open, so server and browser can send messages at any time. Used for chat and live updates.

@app.websocket('/chat')
async def chat(ws: WebSocket):
    await ws.accept()
    while True:
        text = await ws.receive_text()
        await ws.send_text(f'You said: {text}')

Level: Freelancer · More FastAPI terms at this level

Updated

In other subjects