i’m sure there is something simple i’m missing, bu...
# http4k
n
i’m sure there is something simple i’m missing, but is there a way to combine a contract and other binded routes? so i don’t have to duplicate
/api/v1
three times here?
d
Yes. You can bind a path string to a routes block (which is composed of a list of other blocks/routes)
n
oh duh, and then i just use
"/" bind contract
d
Don't even think you need that bind. Because the contract is already a RoutingHttpHandler you can just omit the path. (Routes() takes a vararg of RHH)
s
I did it like this, but didnt have contracts
Copy code
val ApiVersioningRouter: (RoutingHttpHandler) -> RoutingHttpHandler = {
 routes(
        "/api/v1" bind it
    )
}
routes(
                    ApiVersioningRouter(
                        someRouter
                    )
                )
d
was thinking this:
Copy code
val app = routes(
        "/api/v1" bind routes(
            contract {
                "/foo" bindContract GET to { Response(Status.OK) }
            },
            routes(
                "/some/other" bind GET to { Response(Status.OK) }
            ),
            "/yet/another" bind GET to { Response(Status.OK) }
        )
    )
so you have
/api/v1/foo
,
/api/v1/some/other
etc...
n
oh, didn’t realize i could just put a contract by itself. neat!