I think the question is about how to do both, complete with something on one level if the path is finished or go one level deeper if there's still more path available.
Try this:
val route = {
pathPrefix("abc") {
// complete with response 'abc'
pathEnd { complete("abc") } ~ // don't forget the twiggles
pathPrefix("def") {
pathEnd { complete("def") } ~
pathPrefix("ghi") {
pathEnd { complete("ghi") } ~
path("jkl") { // path already includes pathEnd, path(x) = pathPrefix(x ~ PathEnd)
complete("jkl")
}
}
}
}
}
Btw. this doesn't match "/abc/" etc., i.e. a path with a trailing slash. If you want to match trailing slashes mandatorily or optionally use pathSingleSlash
or pathEndOrSingleSlash
instead of pathEnd
.