I'm looking for some way of converting a function which takes basic parameter types and using it to process an akka HttpRequest
. I want the Path
to be automatically processed and passed to the function.
As an example, given some function
def foobar(str : String, i : Int, l : Long) : String = ???
It would be useful to have a way of "lifting" the function to process a Path
. An example URL Path could be
/foobar/einstein/42/2016
The lifting function would look something like:
import akka.http.scaladsl.model.Uri.Path
import akka.http.scaladsl.server.Directive
type SomeFunctionType = ???
def lifter(function : SomeFunctionType, path : Path) : Directive = {
val funcResult = ??? //somehow call function on the Path elements
complete(funcResult)
}
Which could then be used in the following way:
val route =
get {
pathPrefix("foobar") {
extractUnmatchedPath { remainingPath =>
lifter(foobar, remainingPath)
}
}
}
This lifting function would have to loop through the function parameter types and convert the corresponding Path section to the matching type before the values are passed into the function. The example URL would be completed with the result of the call foobar("enstein", 42, 2016)
.
Is there anyway to do this in the libraries? If not, is there a way to define lifter?
Thank you in advance for your consideration and response.