Is there any trick for how to create an empty Rout...
# http4k
l
Is there any trick for how to create an empty RoutingHttpHandler? When I try to anything like
routes(emptyList())
I get:
Exception in thread "main" java.lang.IllegalArgumentException: No routes added!
at org.http4k.routing.RoutingHandler.<init>(RoutingHandler.kt:19)
at org.http4k.routing.RoutingHttpHandler.<init>(http.kt:23)
My use case is assembling routes from different "route providers" that may or not produce any routes. For example, I have a "ClockProvider" that, when configured for test, exposes an endpoint to set a controlled clock and otherwise exposes no such endpoint.
Copy code
routes(
  "/api" bind routes(
    "/login" bind Method.POST to authenticationEndpoints.login,
  ),
  clockProvider.routes, // trying to sometimes return no routes here
  uiEndpoints.routes,
)
j
One possible downside of that approach is that you cannot run multiple parallel tests, as there is only one time in the system. A different approach might be to have a per-request clock, which could be set in a filter. Various mechanisms could be used to ensure that this filter wasn't available in non-test environments.
That's not really answering your question, I realise.
d
you can use an
orElse bind { Response(NOT_FOUND} }
as a default