Does tapir zio-http support websockets

Hello folks,

I am trying to set up a zio-http server that expose a couple of websockets endpoint with tapir-zio-http-server, however ZioHttpInterpreter seems to be expecting to get a list of endpoint with ZioStreams only but using webSocketBody construct generate and endpoint with ZioStreams and WebSockets.

Question is there a way to support webSockets with ZioHttp?

object WebSocketApp extends zio.ZIOAppDefault {

  override def run: ZIO[Any with ZIOAppArgs with Scope, Any, Any] = {

    val pipe: stream.Stream[Throwable, WebSocketFrame] => stream.Stream[Throwable, WebSocketFrame] =
      (s: stream.Stream[Throwable, WebSocketFrame]) => s.map(v => WebSocketFrame.text(s"echo: $v"))

    val we: ZServerEndpoint[Nothing, ZioStreams] =
      endpoint
        .in("ws")
        .out(webSocketBodyRaw(ZioStreams))
        .zServerLogic(_ => ZIO.succeed(pipe))

    val interpreter = ZioHttpInterpreter()
    val http        = interpreter.toHttp(we)

    Server.install(http.withDefaultErrorResponse)

  }

}

Websockets aren’t yet implemented in the ZIO Http interpreter. Please vote on the issue, if you’d like to see this implemented, and/or create a PR on your own! :slight_smile:

1 Like

Hey @adamw ,

thank you for your response.

I have opened a draft PR with initial implementation for web socket support for zio-http, I would appreciate it if I can get an early feedback.