http4s
defines a web application as a function of requests and response, just like:
Request => Response
As we are accessing to some resource like dbs, files or even the network, there will be involved some effect in the response, so:
Request => F[Response]
Being F
the (side) effect affecting the response.
Also, some times there won't be response at all:
Request => F[Option[Response]]
The way http4s chose to represent this function is via a Kleisli monad, which for a types A
, B
and a type constructor F[_]
produces A => F[B]
and is defined like:
Kleisli[F[_], A, B]
to produce A => F[B]
http4s uses a Kleili to define the Request/Response function, the routes:
Kleisli[OptionT[F, *], Request, Response]
Given the OptionT
is a monad transformer defined as OptionT[F, A]
-> F[Option[A]]
(OptionT[Future, String]
is Future[Option[String]]
), the Kleisli just above is translated as:
Request => OptionT[F, Response]
which is
Request => F[Option[Response]]
which is the definition of a route aka Request/Response round.
From the dirty notes: