0

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!

helencrump
  • 1,351
  • 1
  • 18
  • 27
  • have you tried `chain.path( 'myEndpoint/:param0/:param1', handler )`? – injecteer Aug 09 '22 at 22:29
  • @injecteer I've just updated the question to be clearer - unfortunately there could be any number of slash-delimited parts to the URL path so I can't rely on there being a set number. – helencrump Aug 09 '22 at 22:31
  • what's the point to have "any number of parts"? put them into GET or POST+ parameters – injecteer Aug 10 '22 at 08:58

0 Answers0