spring-framework / org.springframework.web.reactive.function.server / coRouter

coRouter

fun coRouter(routes: CoRouterFunctionDsl.() -> Unit): RouterFunction<ServerResponse>

Allow to create easily a WebFlux.fn RouterFunction with a Coroutines router Kotlin DSL.

Example:

@Configuration
class RouterConfiguration {

	@Bean
	fun mainRouter(userHandler: UserHandler) = coRouter {
		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

router

Since
5.2