WebSockets is a bidirectional communication channel that can be established at the request of the client. While websocket communication is not really part of a standard REST api, it has many uses and can easily be used together with one.
Details
A handler for a websocket message is much simpler than for requests in general since it doesn't have to concern itself with methods, paths, and responses. Any message handler registered will get called in sequence when a websocket message is recieved from a client. Still, a few expectations apply
Handler Arguments
The handler can take any of the following arguments:
message
: Either a raw vector if the message recieved is in binary form or a single string, giving the message sent from the clientserver
: The Plumber2 object representing your server implementationclient_id
: A string uniquely identifying the session the request comes fromrequest
: The request that was initially used to establish the websocket connection with the client as a reqres::Request object
Handler Return Value
It is not expected that a websocket message sends a response and thus the handler is not required to do anything like that. However, if the handler returns either a raw vector or a single string it is taken as a signal to send this back to the client. Any other return value is silently ignored.