FastAPI · Decorator
@app.websocket
@app.websocket(path) registers an asynchronous WebSocket endpoint. The handler accepts the connection, receives messages, and sends responses.
Last updated
Syntax
@app.websocket(path)
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.
SubscribeRelated
WebSocketWebSocketDisconnectWebSocketExceptionDependsTestClientAPIRouter