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

Tamara

03/22/2024, 4:21 PM
Is there a way to join 2 http handlers together? i.e if the path isn't covered by the first http handler, fallback to the second?
d

dave

03/22/2024, 4:25 PM
that's entirely what routing is for...
you can selectively match on anything in the request
t

Tamara

03/22/2024, 4:26 PM
So I have two http handlers that already have their own routing. I have a first http handler which has a few routes that all our applications use. And a second http handler with routes for a specific application. I guess I probably want the first http handler to instead be a Filter?
d

dave

03/22/2024, 4:26 PM
no - you can compose 2 routes blocks together
t

Tamara

03/22/2024, 4:27 PM
Ok thanks. I think the spanner in the works is that we're using krouton for that first http handler, and I'm not sure how to get our application specific RoutedHttpHandler to play nicely with what that spits out. I'll take another look at the docs
d

dave

03/22/2024, 4:28 PM
Copy code
val a = routes(
    routes("/foo" bind Method.GET to { Response(OK).body("hellofoo") }),
    routes("/bar" bind Method.GET to { Response(OK).body("hellobar") }),
)
👍 1
I'm not sure how krouton works in terms of exposing a RoutingHttpHandler
s

s4nchez

03/22/2024, 5:36 PM
From memory, krouton turns routing logic into a single HttpHandler.
d

dave

03/22/2024, 5:40 PM
You could fallback on anothr handler using a custom filter - this should be trivial to write