scalahttp4s

BlazeServerBuilder asking for extra parameter


I'm trying to write a simple http server in scala with http4. But when I follow tutorials to create a BlazeServer builder, it will say that I need to supply a Timer[IO] (gives me the error Unspecified value parameters: timer: Timer[IO]), which I can't seem to find any information on why.

val server = BlazeServerBuilder[IO](global)

  

Solution

  • As Luis said, probably worth using the scala seed for http4s quickstart by calling

    $ sbt new http4s/http4s.g8 --branch 0.23

    This will give you a good idea about how to put together the server and routes and config)

    In regards to your question, if you are using Blaze, you can see that timer is one of the implicit parametera for apply, this is the signature (in 0.21.9)

      def apply[F[_]](executionContext: ExecutionContext)(implicit
          F: ConcurrentEffect[F],
          timer: Timer[F]): BlazeServerBuilder[F] 
    

    you can create an implicit timer like this, assuming you have an implicit execution context (in the code below, that is ec)

    implicit val timer: Timer[IO] = IO.timer(ec)