akka/akka-http

WebSockets should use standard marshallers via TextMessage

Open

#281 opened on Sep 12, 2016

View on GitHub
 (1 comment) (1 reaction) (0 assignees)Scala (598 forks)batch import
1 - triagedhelp wantedt:websocket

Repository metrics

Stars
 (1,311 stars)
PR merge metrics
 (Avg merge 1d 10h) (2 merged PRs in 30d)

Description

Issue by fommil Sunday Jul 12, 2015 at 11:36 GMT Originally opened as https://github.com/akka/akka/issues/17969


When using the new handleWebsocketMessages it is probably pretty reasonable to expect that the same marshallers will be used here as in the REST API (and at least the user could provide an implicit ToResponseMarshallable in the scope). However, handleWebsocketMessages expects a Flow[Message, Message, _] which demands that users manually implement the marshalling.

This results in this level of boilerplate:

        val flow = Flow[Message].collect {
          case TextMessage.Strict(msg) =>
            msg.parseJson.convertTo[RpcRequestEnvelope]
          // ignores everything else
        }.via(Flow.wrap(sink, source)((_, _) => ())).map {
          case e: RpcResponseEnvelope =>
            TextMessage.Strict(e.toJson.prettyPrint): Message
        }

Contributor guide