The <Advanced routing guide> shows how to add a gr...
# http4k
a
The Advanced routing guide shows how to add a greedy path matcher to capture the rest of the path after a certain point
Copy code
"/pattern/{rest:.*}" bind { req: Request -> Response(OK).body(req.path("rest") ?: "") }
I've been unable to replicate this for
http4k-contract
in a way it will work in a Swagger UI. I've even tried making a lens so it can fit in to the
ContractRoute
definition, like:
Copy code
val restLens = Path.regex(".*").of("rest")
val route = "pattern" / restLens
But it just results in a 404. Has anyone ever gotten this to work with Swagger UI?
Ah, it came to me immediately after posting. This lens works:
Copy code
val restLens = Path.string().of("rest:.*")
d
wow! I absolutely 100% thought that would not work! Thank you for the lesson! 🤣
a
Maybe it's entirely coincidental that the implementation allows the greediness. I should maybe add a test to ensure it doesn't get broken by accident.
a
Out of curiosity, what's the use case here? It's always interesting to look at the use cases behind these things :)
a
We've got some old weird proxies that need to be maintained. They're used to communicate to IOT devices that maintain a persistent connection with us. Instead of setting an HTTP proxy in our requests, I have to maintain a connection format like:
Copy code
http://<proxy-host>/<device-token>/<target-uri>
where the
device-token
is used to lookup the IOT device's connection. We get the connection, and then send the device something like
Copy code
<http://localhost/><target-uri>
In most cases, we're actually communicating a custom TCP protocol, but the HTTP request above illustrates the point.