0
votes

In a demo project, https://github.com/chbatey/akka-http-typed the following code exists, which compiles but I can't understand how is it that the expression "Http()(untypedSystem).bindAndHandle(routes.userRoutes, "localhost", 8080)" can compile given that the bindAndHandle method takes the parameters below (so first one should be a Flow, but it is a Route, i.e. a RequestContext ⇒ Future[RouteResult] function type).

In another project, I get the compilation error, which I can understand, because the actual parameter has type Route, but the declared type of the first argument if Flow.

Please advice.

//def bindAndHandle(
//    handler:   Flow[HttpRequest, HttpResponse, Any],
//    interface: String, port: Int = DefaultPortForProtocol,
//    connectionContext: ConnectionContext = defaultServerHttpContext,
val serverBinding: Future[Http.ServerBinding] = Http()(untypedSystem).bindAndHandle(routes.userRoutes, "localhost", 8080)
//type of routes.userRoutes is Route
//where type Route = RequestContext ⇒ Future[RouteResult]
//how can it be that this compiles? In another project it does not (which makes more sense to me)
1

1 Answers

5
votes

There is an implicit conversion from Route to Flow[HttpRequest, HttpResponse, NotUsed] in the companion object of the RouteResult type, called route2HandlerFlow.

It is not clear why this is not being found in your other project, but post that as a separate question if it continues to be a problem.