An endpoint should echo a part of the request path. There are two variants of the request:
<host>/xyz-<token>/
<host>/xyz-<token>.txt
The token
part is what I would like to extract. However, I am only able to match the second variant and not the first. The request is being rejected with a 'The requested resource could not be found'
The slash seems to prevent the matching. When I remove the slash from the first variant, it matches, when I append a slash to the second one, it stops matching. I have tried several variants, the simplest reproducible being:
val tokenRoute: Route =
pathSuffix(s"xyz-(.+)".r) { token: String =>
pathEndOrSingleSlash {
complete(token.split('.').head)
}
}
Adding or removing a slash to the end of the regex seems to have no effect. Removing the pathEndOrSingleSlash
directive neither.
What am I misunderstanding here?
EDIT:
I have been oversimplifying - the matched path should also include
<host>/<prefix>/xyz-<token>/
<host>/<prefix>/xyz-<token>.txt
which pathPrefix
does not handle - requests including the prefix, e.g <host>/abc/xyz-<token>/
are rejected with 'The requested resource could not be found'
.
I want to simply ignore the prefix, just capture the token incoming to any path.