Akka-http: full stream request

Suppose I set the arbitrarily complex Flow[HttpRequest, HttpResponse, Unit] .

I can already use the specified stream to handle incoming requests with

 Http().bindAndHandle(flow, "0.0.0.0", 8080) 

Now I would like to add a log using some existing directive, for example logRequestResult("my-service"){...} Is there a way to combine this directive with my stream? I think I'm looking for another directive, something like

 def completeWithFlow(flow: Flow): Route 

Is this even possible?

NB: logRequestResult is an example, my question relates to any Directive that may be useful.

+7
akka-stream
source share
2 answers

Turns off one (and possibly the only) way - to connect and materialize a new stream and pass the request allocated to it. Example below

  val myFlow: Flow[HttpRequest, HttpResponse, NotUsed] = ??? val route = get { logRequestResult("my-service") { extract(_.request) { req ⇒ val futureResponse = Source.single(req).via(myFlow).runWith(Sink.head) complete(futureResponse) } } } Http().bindAndHandle(route, "127.0.0.1", 9000) 
+4
source

http://doc.akka.io/docs/akka/2.4.2/scala/http/routing-dsl/overview.html

Are you looking for route2HandlerFlow or Route.handlerFlow ?

I believe Route.handlerFlow will work based on implicit s.

eg /

 val serverBinding = Http().bindAndHandle(interface = "0.0.0.0", port = 8080, handler = route2HandlerFlow(mainFlow())) 
0
source

All Articles