Thank you very much, this article was very helpful. I think something similar should be included to akka-http documentation
On Friday, June 12, 2015 at 10:17:47 AM UTC+3, Sam D wrote: > > Anton, > > I think you are looking for http headers of the request? > http://spray.io/documentation/1.2.2/spray-routing/header-directives/headerValueByName/ > > or > http://doc.akka.io/api/akka-stream-and-http-experimental/1.0-RC3/index.html#akka.http.scaladsl.server.directives.HeaderDirectives > > This shows how you can get access to the ctx object. > > http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-RC2/scala/http/directives.html > > https://github.com/akka/akka/blob/release-2.3-dev/akka-http/src/main/scala/akka/http/scaladsl/server/directives/HeaderDirectives.scala > > val route: Route = { > logRequestResult("akka-http-test") { > path("ping") { > get { > headerValueByName("foo") { foo => > complete(foo) > } > } > } > } > } > > val route: Route = { > logRequestResult("akka-http-test") { > path("ping") { > get { ctx => > // probably not a good access method > ctx.complete(ctx.request.headers.find { header => > header.lowercaseName() == "foo" }.get.value()) > } > } > } > } > > I think the word magnet meaning comes from the closer all the route > directives match up to the request it pulls toward the complete call (could > be implicit). My understanding of the magnet pattern comes from reading > this Spray (predicessor of akka-http) doc > http://spray.io/blog/2012-12-13-the-magnet-pattern/ . > > The routing DSL is a higher level abstraction and depending on the use > case might not be necessary and you can use pattern matching instead. The > low level abstraction uses pattern matching > http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-RC3/scala/http/low-level-server-side-api.html > > > > On Thursday, June 11, 2015 at 11:55:28 AM UTC-4, Anton Kulaga wrote: >> >> Hi all, >> >> I am writing a webapp based on akka-http and I got stuck because of lack >> of understanding of several things: >> >> 1) If I have I directive, say >> >> def auth = path("users" / "login") >> { >> parameters("username","password") { (name,password) ⇒ >> //some other code >> } >> >> How can I extract request context from it? I need not only name+password >> but also request context itself >> >> 2) How do all those mysterious Magnets work? Are you going to add their >> description to docs of RC4? When I start digging into the source code to >> understand what is happening I often come around them and it is extremely >> hard to understand what exactly is happening. >> >> -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
