I use akka directives to match a specific path pattern:
/item/quantity
Examples:
/apples/100 /bananas/200
Possible points (for example, "apples", "bananas", ...) are not known in advance, so hard coding of elements using path not an option.
However, I cannot find a PathMatcher that retrieves the path header. I'm looking for something like a form
val route = get { path(PathHeadAsString) { item : String => path(IntNumber) { qty : Int => complete(s"item: $item quantity: $qty") } ~ complete("no quantity specified") } ~ complete("no item specified") }
Where
Get("/apples/100") ~> route ~> check { responseAs[String] shouldEqual "item: apples quantity: 100" }
Is there a way to extract the first segment of the path?
Matches path(segment) will not match if the number is in the path.
I obviously could use path(segments) to get the List[String] elements of the path, but I would have to manually extract the list and the tail of the list manually, which seems inelegant.
Thank you in advance for your consideration and response.
source share