I often find myself proxying some routes by defini...
# http4k
l
I often find myself proxying some routes by defining a RoutingHttpHandler like this:
Copy code
routes(
  "/something" bind Method.GET to somethingHandler,
  "/api/" bind proxyClient,
  "/api/{path:.*}" bind proxyClient,
)
I've found that I have to declare both the
/api/
and
/api/{path:.*}
routes to match the /api path and all subpaths. It feels a little silly I couldn't find a way to express this in one path definition. Is there an approach or syntax I've overlooked?
s
@leonhardt, I'm afraid you haven't missed anything. Currently, because of the way http4k defines URI Templates and matches routes, you need to define those twice
🍻 1
thank you color 1
d
Maybe ... we've rewritten the routing for V6 but I suspect it will still not work - it might be due to the URL template trims slashes before matching.
thank you color 1
l
Thank you both for the insight/confirmation. If it doesn't work in v6 either, I'll understand! I think it's just a bit of a tripping hazard because I don't think the behavior is possible to intuit without experimentation. Mainly, the
.*
syntax made me think it would work because if it that expression were regex, it would match no path as well, (as opposed to
.+
).
I'll certainly keep an eye on this and see if there's an improvement when you release v6!