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

The goal is to have better consistency between Java
and Kotlin functional Web API.
This commit is contained in:
Sebastien Deleuze 2017-03-15 17:21:04 +01:00
parent abc0c6e3e8
commit 170057005e
2 changed files with 4 additions and 4 deletions

View File

@ -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())
}

View File

@ -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 {
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)