https://kotlinlang.org logo
#http4k
Title
# http4k
n

Nezteb

04/24/2019, 10:33 PM
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

dave

04/25/2019, 2:35 AM
Yes. You can bind a path string to a routes block (which is composed of a list of other blocks/routes)
n

Nezteb

04/25/2019, 2:49 AM
oh duh, and then i just use
"/" bind contract
d

dave

04/25/2019, 5:03 AM
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

sahil Lone

04/25/2019, 8:03 AM
I did it like this, but didnt have contracts
Copy code
val ApiVersioningRouter: (RoutingHttpHandler) -> RoutingHttpHandler = {
 routes(
        "/api/v1" bind it
    )
}
routes(
                    ApiVersioningRouter(
                        someRouter
                    )
                )
d

dave

04/25/2019, 8:23 AM
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

Nezteb

04/25/2019, 2:40 PM
oh, didn’t realize i could just put a contract by itself. neat!
4 Views