fun router(routes: RouterFunctionDsl.() -> Unit): RouterFunction<ServerResponse>
Allow to create easily a RouterFunction<ServerResponse>
from a Kotlin router DSL based
on the same building blocks than the Java one (RouterFunction, RequestPredicate,
HandlerFunction).
Example:
@Configuration
class ApplicationRoutes(val userHandler: UserHandler) {
@Bean
fun mainRouter() = router {
accept(TEXT_HTML).nest {
(GET("/user/") or GET("/users/")).invoke(userHandler::findAllView)
GET("/users/{login}", userHandler::findViewById)
}
accept(APPLICATION_JSON).nest {
(GET("/api/user/") or GET("/api/users/")).invoke(userHandler::findAll)
POST("/api/users/", userHandler::create)
}
}
}
Author
Sebastien Deleuze
See Also
Since
5.0