Alberto Cabello
01/28/2025, 4:35 AMclass A {
fun getHandler(): RoutingHttpHandler {.....}
}
fun main() {
val app = routes(
"/A" bind A.getHandler()
}
In looking to replicate that with contracts, I found you can't really. Looking into making a contribution to the codebase, how would you guys want that to look? I can PR the repo fairly easily with my first thought which was a withRoutesFrom
method that would look like
class A {
fun getHandler(): ContractRoutingHandler {...}
}
fun main() {
val app = contract {...}.withRoutesFrom("/A" bind A.getHandler(), "/B" bind B.getHandler()...
}
Is this something interesting, or is there another solution you guys have had in mind that would be preferred? Maybe I can tackle itdave
01/28/2025, 5:24 AMdave
01/28/2025, 5:27 AMAlberto Cabello
01/28/2025, 5:40 AMList<ContractRoutes>
, I can't "/prefix" bind
them. I'd have to manually write out something like
contract {
routes.plusAssign(A.getRoutes())
routes.plusAssing(B.getRoutes())
...
}
And in the routes themselves, I'd have to put the prefix every time. A minor grievance, but one that's not present in non-contract routing, and would be alleviated if I could somehow reference the actual routes from a contract.
If I expose a ContractRoutingHttpHandler
I can't compose them without losing the OpenAPI spec since routes("prefix" bind ContractRoutingHttpHandler)
strips the spec off, and I can't just do
contract {
routes.plusAssign(("/prefix" bind someOtherContract).routes)
}
Since the route object is privatedave
01/28/2025, 5:48 AMAlberto Cabello
01/28/2025, 6:03 AMAlberto Cabello
01/28/2025, 6:05 AMplusAssign
them all, I was just hoping to get something nicer and more inline with how it is with non-contract routesdave
01/28/2025, 6:09 AMAlberto Cabello
01/28/2025, 6:15 AMIt's not especially your wording - its that it's easier for people to play with when it's already code.That's true!
when we get the inspirationTotally get it, I figured I'd ask if the proposed
withRoutesFrom
was something you'd be interested in before I put in a PR for it