You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add_websocket_route() was removed from the root Starlette application class as part of a deliberate API narrowing — the root class is being gradually simplified to not re-export convenience methods that properly belong on Router. The functionality itself is not gone.
Is Router.add_websocket_route() still valid?
Yes. The method lives on Router, and since Starlette.router is a public Router instance, you can call it directly:
This is preferred because routes are immutable after the ASGI lifecycle starts — dynamically adding routes post-startup can cause issues with route detection in certain ASGI middleware stacks.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
add_websocket_route() helper was removed from root Starlette application class in the following commit:
f99e11f#diff-3eb07c0eea72d98f1b844e07844c2a68b7c11c63956b67d5afdd9c7f79ab946fR8-L152
Why?
This method is still present in Router:
starlette/starlette/routing.py
Line 740 in edcc79e
So I assume it is still a valid API for adding new Websocket routes to an existing router.
All reactions