I've got a Ratpack application and I'm trying to configure an endpoint for GET requests which delegates to a handler based on a prefix. However, my URL path may contain multiple slashes, which I'd want to capture and use in my handler.
Example:
Given the requests http://localhost:8080/myEndpoint/foo/bar/
and http://localhost:8080/myEndpoint/baz/qux/fred/
, I'd like to delegate to my handler MyEndpointHandler
in both cases since the request paths are prefixed by myEndpoint
. Inside MyEndpointHandler
, I'd need to retrieve /foo/bar
and /baz/qux/fred/
respectively, since these are the remaining parts of the path after the /myEndpoint
prefix.
My original thinking was to do something like:
chain.path("myEndpoint/:restOfPath?", new MyEndpointHandler());
However this only seems to work for one slash (i.e. a request to http://localhost:8080/myEndpoint/foo
is fine and I have access to /foo
, but a request to http://localhost:8080/myEndpoint/foo/bar
returns a 404).
I have also tried:
chain.prefix("myEndpoint", c1 -> c1.path(new MyEndpointHandler()));
However this returned a 404 for all requests regardless of the path after /myEndpoint
.
Looking at the docs, https://ratpack.io/manual/current/api/ratpack/core/path/PathBinding.html#getPastBinding() seems like exactly what I need to be able to get the /foo/bar
part of these requests, but I'm struggling to bind my handler to the chain in the right way to be able to access this "past binding".
Thanks in advance for the help!