Senia's answer is helpful in understanding the Spray-routing directives and how they use HLists to do their work. But I get the impression you were really just interested in the Scala constructs used in
path( "foo" / Segment / Segment ) { (a,b) => ... }
It sounds as though you are interpreting this as special Scala syntax that in some way connects those two Segment
instances to a
and b
. That is not the case at all.
path( "foo" / Segment / Segment )
is just an ordinary call to path
with a single argument, an expression involving two calls to a /
method. Nothing fancy, just an ordinary method invocation.
The result of that call is a function which wants another function -- the thing you want to happen when a matching request comes in -- as an argument. That's what this part is:
{ (a,b) => ... }
It's just a function with two arguments. The first part (the invocation of path
) and the second part (what you want done when a matching message is received) are not syntactically connected in any way. They are completely separate to Scala. However, Spray's semantics connects them: the first part creates a function that will call the second part when a matching message is received.