Are wildcard/splat routes possible?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Are wildcard/splat routes possible?

Tyler
I'm trying to implement a handler which can handle `/zk/*/info` which would serve up `/zk/root/info` as well as routes like `/zk/root/child/grandchild/info` as well.

I've seen [the regex support](https://github.com/timyates/ratpack/commit/ca667416c5547c6bef0b71a1fb09e0985ca27c78) but I can't figure out how to make it work.
rus
Reply | Threaded
Open this post in threaded view
|

Re: Are wildcard/splat routes possible?

rus
Regex makes my brain hurt but this works for me

handler("zk/::.+/info") {
  ........
}

The "::" is saying that this is the start of a literal with a pattern.  As opposed to ":a:" which is a token with a pattern i.e. the regex would be made available to you in a path token of "a"

The rest i.e. ".+" is the regex.  In this case match any character 1 or more times.