tapir
                                
                                 tapir copied to clipboard
                                
                                    tapir copied to clipboard
                            
                            
                            
                        Integration tapir web soket endpoint to zio-http server [Feature]
Tapir version: 0.18.3
Scala version: 2.13.6
Can't integrate tapir websocket endpoint to zio-http server.
Is there a way to do this? Perhaps this feature hasn't been implemented yet?
I try something like this:
`import sttp.capabilities.WebSockets import sttp.capabilities.zio.ZioStreams import sttp.tapir._ import sttp.tapir.server.ziohttp.ZioHttpInterpreter import zhttp.http.HttpApp import zhttp.service._ import zio._ import zio.stream._
object TapirWebSocketAdvanced extends App { val wsEndpoint: Endpoint[Unit, Unit, Stream[Throwable, String] => Stream[Throwable, String], ZioStreams with WebSockets] = endpoint .get .in("echo") .out(webSocketBodyString, CodecFormat.TextPlain, String, CodecFormat.TextPlain)
val echo: Stream[Throwable, String] => Stream[Throwable, String] = s => s
val wsRoutes: HttpApp[Any, Throwable] = ZioHttpInterpreter().toHttp(wsEndpoint)(_ => echo)
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = Server.start(8080, wsRoutes).exitCode }`
Thanks for the answer, maybe I'm doing something wrong.
Now you haven't said what is actually the problem, and it's always smart to specify what the actual problem is instead of just stating that it doesn't work as it makes it easier to answer your question, but at least an obvious problem here is that the zio-http interpreter doesn't support WebSockets. So you cannot make it work with a WebSocket-based endpoint until someone implements support for that in the interpreter. I am guessing that is the problem you have encountered (which is technically not a bug, it's just a feature that isn't implemented).
ok thanks for this issue report, now I understand why my websocket attemps with zio-http doesn't compile.
Some extracts from the example case I was working on :
  type DataRecorderEnv = DataRecorderService
  val serviceEventsEndpoint =
    systemEndpoint
      .name("Application service events")
      .summary("Receive application service events")
      .description("Receive broadcasted application service events")
      .in("events")
      .out(webSocketBody[ClientMessage, CodecFormat.Json, ServerMessage, CodecFormat.Json](ZioStreams))
  val serviceEventsEndpointLogic =
    ZIO.succeed((clientMessageStream: Stream[Throwable, ClientMessage]) =>
      ZStream
        .tick(500.millis)
        .zipWith(ZStream("A", "B", "C", "D").repeat(Schedule.forever))((_, c) => ServerMessage(c))
    )
  val serviceEventsEndpointImpl =
    serviceEventsEndpoint
      .zServerLogic[DataRecorderEnv](_ => serviceEventsEndpointLogic)
// ...
  def webService = for {
    _        <- ZIO.logInfo("Starting webService")
    routes    = apiRoutes ++ apiDocRoutes
    httpApp   = ZioHttpInterpreter().toHttp(routes)
    zservice <- zhttp.service.Server.start(8080, httpApp)
  } yield zservice
Compilation fails on the toHttp(routes) call with the following error message :
None of the overloaded alternatives of method toHttp in trait ZioHttpInterpreter with types
 (ses: 
  List[sttp.tapir.ztapir.ZServerEndpoint[R, sttp.capabilities.zio.ZioStreams]]
): zhttp.http.Http[R, Throwable, zhttp.http.Request, zhttp.http.Response]
 (se: sttp.tapir.ztapir.ZServerEndpoint[R, sttp.capabilities.zio.ZioStreams]): 
  zhttp.http.Http[R, Throwable, zhttp.http.Request, zhttp.http.Response]
match arguments ((routes : 
  List[
    sttp.tapir.ztapir.ZServerEndpoint[
      fr.janalyse.datarecorder.Main.DataRecorderEnv
    , sttp.capabilities.zio.ZioStreams & sttp.capabilities.WebSockets]
  ]
))
    httpApp   = ZioHttpInterpreter().toHttp(routes)
This works since https://github.com/softwaremill/tapir/releases/tag/v1.7.4 I believe.
@vladimir-lu right, closing this, thanks! :)