Add no path HTTP method variants for route builder
This commit adds two overloaded methods for each HTTP method in the WebFlux.fn and WebMvc.fn route builders: one method taking just a handler function, the other a request predicate and handler function. After this commit, it is no longer required to provide a String path, which is particularly useful when nesting routes, and the path would be "". Closes gh-25752
This commit is contained in:
@@ -587,7 +587,7 @@ improved in the following way by using nested routes:
|
||||
RouterFunction<ServerResponse> route = route()
|
||||
.path("/person", builder -> builder // <1>
|
||||
.GET("/{id}", accept(APPLICATION_JSON), handler::getPerson)
|
||||
.GET("", accept(APPLICATION_JSON), handler::listPeople)
|
||||
.GET(accept(APPLICATION_JSON), handler::listPeople)
|
||||
.POST("/person", handler::createPerson))
|
||||
.build();
|
||||
----
|
||||
@@ -599,7 +599,7 @@ RouterFunction<ServerResponse> route = route()
|
||||
val route = coRouter {
|
||||
"/person".nest {
|
||||
GET("/{id}", accept(APPLICATION_JSON), handler::getPerson)
|
||||
GET("", accept(APPLICATION_JSON), handler::listPeople)
|
||||
GET(accept(APPLICATION_JSON), handler::listPeople)
|
||||
POST("/person", handler::createPerson)
|
||||
}
|
||||
}
|
||||
@@ -617,7 +617,7 @@ We can further improve by using the `nest` method together with `accept`:
|
||||
.path("/person", b1 -> b1
|
||||
.nest(accept(APPLICATION_JSON), b2 -> b2
|
||||
.GET("/{id}", handler::getPerson)
|
||||
.GET("", handler::listPeople))
|
||||
.GET(handler::listPeople))
|
||||
.POST("/person", handler::createPerson))
|
||||
.build();
|
||||
----
|
||||
@@ -628,7 +628,7 @@ We can further improve by using the `nest` method together with `accept`:
|
||||
"/person".nest {
|
||||
accept(APPLICATION_JSON).nest {
|
||||
GET("/{id}", handler::getPerson)
|
||||
GET("", handler::listPeople)
|
||||
GET(handler::listPeople)
|
||||
POST("/person", handler::createPerson)
|
||||
}
|
||||
}
|
||||
@@ -760,7 +760,7 @@ For instance, consider the following example:
|
||||
.path("/person", b1 -> b1
|
||||
.nest(accept(APPLICATION_JSON), b2 -> b2
|
||||
.GET("/{id}", handler::getPerson)
|
||||
.GET("", handler::listPeople)
|
||||
.GET(handler::listPeople)
|
||||
.before(request -> ServerRequest.from(request) // <1>
|
||||
.header("X-RequestHeader", "Value")
|
||||
.build()))
|
||||
@@ -812,7 +812,7 @@ The following example shows how to do so:
|
||||
.path("/person", b1 -> b1
|
||||
.nest(accept(APPLICATION_JSON), b2 -> b2
|
||||
.GET("/{id}", handler::getPerson)
|
||||
.GET("", handler::listPeople))
|
||||
.GET(handler::listPeople))
|
||||
.POST("/person", handler::createPerson))
|
||||
.filter((request, next) -> {
|
||||
if (securityManager.allowAccessTo(request.path())) {
|
||||
|
||||
@@ -555,7 +555,7 @@ For instance, the last few lines of the example above can be improved in the fol
|
||||
RouterFunction<ServerResponse> route = route()
|
||||
.path("/person", builder -> builder // <1>
|
||||
.GET("/{id}", accept(APPLICATION_JSON), handler::getPerson)
|
||||
.GET("", accept(APPLICATION_JSON), handler::listPeople)
|
||||
.GET(accept(APPLICATION_JSON), handler::listPeople)
|
||||
.POST("/person", handler::createPerson))
|
||||
.build();
|
||||
----
|
||||
@@ -569,7 +569,7 @@ RouterFunction<ServerResponse> route = route()
|
||||
val route = router {
|
||||
"/person".nest {
|
||||
GET("/{id}", accept(APPLICATION_JSON), handler::getPerson)
|
||||
GET("", accept(APPLICATION_JSON), handler::listPeople)
|
||||
GET(accept(APPLICATION_JSON), handler::listPeople)
|
||||
POST("/person", handler::createPerson)
|
||||
}
|
||||
}
|
||||
@@ -587,7 +587,7 @@ We can further improve by using the `nest` method together with `accept`:
|
||||
.path("/person", b1 -> b1
|
||||
.nest(accept(APPLICATION_JSON), b2 -> b2
|
||||
.GET("/{id}", handler::getPerson)
|
||||
.GET("", handler::listPeople))
|
||||
.GET(handler::listPeople))
|
||||
.POST("/person", handler::createPerson))
|
||||
.build();
|
||||
----
|
||||
@@ -719,7 +719,7 @@ For instance, consider the following example:
|
||||
.path("/person", b1 -> b1
|
||||
.nest(accept(APPLICATION_JSON), b2 -> b2
|
||||
.GET("/{id}", handler::getPerson)
|
||||
.GET("", handler::listPeople)
|
||||
.GET(handler::listPeople)
|
||||
.before(request -> ServerRequest.from(request) // <1>
|
||||
.header("X-RequestHeader", "Value")
|
||||
.build()))
|
||||
@@ -738,7 +738,7 @@ For instance, consider the following example:
|
||||
val route = router {
|
||||
"/person".nest {
|
||||
GET("/{id}", handler::getPerson)
|
||||
GET("", handler::listPeople)
|
||||
GET(handler::listPeople)
|
||||
before { // <1>
|
||||
ServerRequest.from(it)
|
||||
.header("X-RequestHeader", "Value").build()
|
||||
@@ -773,7 +773,7 @@ The following example shows how to do so:
|
||||
.path("/person", b1 -> b1
|
||||
.nest(accept(APPLICATION_JSON), b2 -> b2
|
||||
.GET("/{id}", handler::getPerson)
|
||||
.GET("", handler::listPeople))
|
||||
.GET(handler::listPeople))
|
||||
.POST("/person", handler::createPerson))
|
||||
.filter((request, next) -> {
|
||||
if (securityManager.allowAccessTo(request.path())) {
|
||||
|
||||
Reference in New Issue
Block a user