Testing with http4s

How can I make this code works with http4s ?

  def backend[I, O](route:
              ServerEndpoint[Any, scala.concurrent.Future] {
                    type SECURITY_INPUT = Unit;
                    type PRINCIPAL = Unit;
                    type INPUT = I;
                    type ERROR_OUTPUT = String;
                    type OUTPUT = O
              }

             ) =
                TapirStubInterpreter(SttpBackendStub.asynchronousFuture)
                            .whenServerEndpoint(route)
                            .thenRunLogic()
                            .backend()

problem is with Future, but I don´t know how to change de Effect

I’d probably need a larger snippet, but I think this should work, as long as your route already uses cats.effect.IO to implement the server logic:

def backend[I, O](route: ServerEndpoint[Any, IO]) =
  TapirStubInterpreter(SttpBackendStub(new CatsMonadError[IO]()))
                            .whenServerEndpoint(route)
                            .thenRunLogic()
                            .backend()

Also, maybe an example project generated using https://adopt-tapir.softwaremill.com will be helpful to understand how to implement a sample endpoint.

1 Like

thank you

problem solved!