Browse Source

Use .nest() instead of .route() in Kotlin Web DSL

The goal is to have better consistency between Java
and Kotlin functional Web API.
pull/1357/merge
Sebastien Deleuze 8 years ago
parent
commit
170057005e
  1. 4
      spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionExtensions.kt
  2. 4
      spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RouterFunctionExtensionsTests.kt

4
spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionExtensions.kt

@ -80,11 +80,11 @@ class RouterDsl { @@ -80,11 +80,11 @@ class RouterDsl {
operator fun RequestPredicate.not(): RequestPredicate = this.negate()
fun RequestPredicate.route(r: Routes) {
fun RequestPredicate.nest(r: Routes) {
routes += RouterFunctions.nest(this, RouterDsl().apply(r).router())
}
fun String.route(r: Routes) {
fun String.nest(r: Routes) {
routes += RouterFunctions.nest(pathPrefix(this), RouterDsl().apply(r).router())
}

4
spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RouterFunctionExtensionsTests.kt

@ -107,7 +107,7 @@ class RouterFunctionExtensionsTests { @@ -107,7 +107,7 @@ class RouterFunctionExtensionsTests {
fun sampleRouter() = router {
(GET("/foo/") or GET("/foos/")) { req -> handle(req) }
"/api".route {
"/api".nest {
POST("/foo/", ::handleFromClass)
PUT("/foo/", :: handleFromClass)
"/foo/" { handleFromClass(it) }
@ -115,7 +115,7 @@ class RouterFunctionExtensionsTests { @@ -115,7 +115,7 @@ class RouterFunctionExtensionsTests {
accept(APPLICATION_ATOM_XML, ::handle)
contentType(APPLICATION_OCTET_STREAM, ::handle)
method(PATCH, ::handle)
headers({ it.accept().contains(APPLICATION_JSON) }).route {
headers({ it.accept().contains(APPLICATION_JSON) }).nest {
GET("/api/foo/", ::handle)
}
headers({ it.header("bar").isNotEmpty() }, ::handle)

Loading…
Cancel
Save