feat: Add query params to websocket requests #485
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To allow interaction with normal HTTP requests we require that additional information can be provided during the upgrade process of a websocket connection.
A common way to facilitate this is by using query paramaters.
Use Case:
Priming state/pre-authorizing sessions:
Suppose we wanted to create an app like firepoker. You could facilitate this entirely over websockets, however it would be more efficient/cost-effective to manage this using a HTTP API instead.
Step 1: Create a new session using an API
POST /api/session
this would provide a token and connection URL for joining the newly created session.
Step 2: Connect to the new session using websockets
Using the token provided in the previous request we will now be able to join the session
new WebSocket("wss://my-websocket-address.com?session=abcd1234")
During connection this information could be used to isolate communcation between websockets that share a session as part of connection storage/management.
This essentially allows for multi-session websocket applications.