3 ms·
If anything the documentation isn't great. Http4s is an advanced library and maybe expects some knowledge about PFP and related datatypes. They should make that
by valenterry 4y ago
If anything the documentation isn't great. Http4s is an advanced library and maybe expects some knowledge about PFP and related datatypes. They should make that clear to everyone imho.
But other than that, running a simple hello-world service with http4s really isn't that hard.
object Main extends StreamApp[IO] {
val helloWorldService = HttpService[IO] {
case GET -> Root / "hello" / name => Ok(s"Hello, $name.")
}
override def stream(args: List[String], requestShutdown: IO[Unit]) =
BlazeBuilder[IO]
.bindHttp(8080, "localhost")
.mountService(helloWorldService, "/")
.serve
}
Yeah, there are a couple of things that are more complex than with other simple webservers. For instance, what is the "IO" thing doing there? Well, http4s flexibly allows you to choose different libraries for handling concurrency without even knowing those libraries. Very few other programming languages are even powerful enough to support something like that, so it obviously confuses people.
And then you need a StreamApp (there are other alternatives but that's the one from the documentation) and people might wonder why - they want a simple request/response webservice and nothing "streaming".
Other than that, I don't think the code is overly complicated.