spring-framework
5.3.39

# router

fun router(routes: RouterFunctionDsl.() -> Unit): RouterFunction<ServerResponse>
Content copied to clipboard

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

Example:

    @Configuration
    class RouterConfiguration {

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

    }

Content copied to clipboard

#### Author

Sebastien Deleuze

Arjen Poutsma

#### Since

5.2