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:
		
							parent
							
								
									abc0c6e3e8
								
							
						
					
					
						commit
						170057005e
					
				| 
						 | 
					@ -80,11 +80,11 @@ class RouterDsl {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	operator fun RequestPredicate.not(): RequestPredicate = this.negate()
 | 
						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())
 | 
							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())
 | 
							routes += RouterFunctions.nest(pathPrefix(this), RouterDsl().apply(r).router())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -107,7 +107,7 @@ class RouterFunctionExtensionsTests {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fun sampleRouter() = router {
 | 
						fun sampleRouter() = router {
 | 
				
			||||||
		(GET("/foo/") or GET("/foos/")) { req -> handle(req) }
 | 
							(GET("/foo/") or GET("/foos/")) { req -> handle(req) }
 | 
				
			||||||
		"/api".route {
 | 
							"/api".nest {
 | 
				
			||||||
			POST("/foo/", ::handleFromClass)
 | 
								POST("/foo/", ::handleFromClass)
 | 
				
			||||||
			PUT("/foo/", :: handleFromClass)
 | 
								PUT("/foo/", :: handleFromClass)
 | 
				
			||||||
			"/foo/"  { handleFromClass(it) }
 | 
								"/foo/"  { handleFromClass(it) }
 | 
				
			||||||
| 
						 | 
					@ -115,7 +115,7 @@ class RouterFunctionExtensionsTests {
 | 
				
			||||||
		accept(APPLICATION_ATOM_XML, ::handle)
 | 
							accept(APPLICATION_ATOM_XML, ::handle)
 | 
				
			||||||
		contentType(APPLICATION_OCTET_STREAM, ::handle)
 | 
							contentType(APPLICATION_OCTET_STREAM, ::handle)
 | 
				
			||||||
		method(PATCH, ::handle)
 | 
							method(PATCH, ::handle)
 | 
				
			||||||
		headers({ it.accept().contains(APPLICATION_JSON) }).route {
 | 
							headers({ it.accept().contains(APPLICATION_JSON) }).nest {
 | 
				
			||||||
			GET("/api/foo/", ::handle)
 | 
								GET("/api/foo/", ::handle)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		headers({ it.header("bar").isNotEmpty() }, ::handle)
 | 
							headers({ it.header("bar").isNotEmpty() }, ::handle)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue