AuthedRoutes with Websocket

Hi,

I am building an Authed websocket route, so have:

val endpoint: Endpoint[Unit, User, ErrorResponse, Pipe[IO, In, Out], capabilities.WebSockets with Context[User] with Fs2Streams[IO]
  ] = …

def thePipe(user: User): fs2.Pipe[IO, In, Out] = …

val serverEndpoints: Full[Unit, Unit, User, ErrorResponse, Pipe[IO, In, Out], WebSockets with Context[User] with Fs2Streams[IO], IO] = 
  endpoint.serverLogicSuccess(user => IO.pure(thePipe(user)))

// Fails to compile 
Http4sServerInterpreter[IO].toContextRoutes(serverEndpoints)

How should the serverEndpoints be interpreted?

(I notice that both Http4sServerInterpreter.toContextRoutes call the private toContextRoutes with None for the webSocketBuilder.)

Compilation error:

overloaded method toContextRoutes with alternatives:
  [T](ses: List[ServerEndpoint[sttp.capabilities.fs2.Fs2Streams[IO] with Context[T],IO]])(implicit evidence$2: scala.reflect.ClassTag[T]): org.ContextRoutes[T,IO] <and>
  [T](se: ServerEndpoint[sttp.capabilities.fs2.Fs2Streams[IO] with Context[T],IO])(implicit evidence$1: scala.reflect.ClassTag[T]): org.ContextRoutes[T,IO]
 cannot be applied to (ServerEndpoint.Full[Unit,Unit,User,ErrorResponse,fs2.Pipe[IO,In,Out,sttp.capabilities.WebSockets with Context[User] with sttp.capabilities.fs2.Fs2Streams[IO],IO])
    Http4sServerInterpreter[IO]().toContextRoutes(serverEndpoints)

Indeed, this method was missing: Add missing toContextWebSocketRoutes method by adamw · Pull Request #4728 · softwaremill/tapir · GitHub

1 Like