Within the Scala ecosystem, the Akka-HTTP library is a popular choice for implementing server-side backends for HTTP APIs. Another popular option is the Play framework, but using a full-blown web framework to just provide a thin API is an overkill in most cases. As most services need a database, the Slick library is another popular choice. This completes the picture of the current landscape. However, while all mentioned libraries are battle-tested and proven to work well, they still have a number of problems.
Problems in the current state of the art
In the domain of functional programming, our main goal is referential transparency, which we define in the following way:
An expression e is referentially transparent if we can replace any occurrences of e in any given program with the result of the evaluation of e without changing the behavior of the program.
Building on that, we need pure functions which are:
Only dependent on their input
Have no side effects
This means that our functions will be referentially transparent.
However, the above-mentioned libraries are built upon Future from Scala, which uses eager evaluation and breaks referential transparency.
Let’s look at an example.