andyD
11/04/2024, 4:00 PMval handler1 = routes("foo" bind GET to { Response(OK) })
val handler2 = routes("bar" bind GET to { Response(OK) })
val combined = handler1 combinedWith handler2
andyD
11/04/2024, 4:01 PMclass Testing {
@Test
fun `works`() {
val handler1 = routes("foo" bind GET to { Response(OK) })
val handler2 = routes("bar" bind GET to { Response(OK) })
val combined = handler1 combinedWith handler2
assertThat(combined(Request(GET, "/foo")).status, equalTo(OK))
assertThat(combined(Request(GET, "/bar")).status, equalTo(OK))
}
}
infix fun HttpHandler.combinedWith(other: HttpHandler): HttpHandler = { request ->
val response = this(request)
if (response.status == Status.NOT_FOUND) {
other(request)
} else {
response
}
}
dave
11/04/2024, 4:03 PMdave
11/04/2024, 4:04 PMandyD
11/04/2024, 4:05 PMval combined = routes(handler1, handler2)
did it - that's what I was looking for.. thanks