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:
parent
d3087537d5
commit
200b33b26a
|
@ -28,6 +28,7 @@ import reactor.core.publisher.Flux;
|
|||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
@ -38,9 +39,9 @@ import org.springframework.util.Assert;
|
|||
*/
|
||||
class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
|
||||
private List<RouterFunction<ServerResponse>> routerFunctions = new ArrayList<>();
|
||||
private final List<RouterFunction<ServerResponse>> routerFunctions = new ArrayList<>();
|
||||
|
||||
private List<HandlerFilterFunction<ServerResponse, ServerResponse>> filterFunctions = new ArrayList<>();
|
||||
private final List<HandlerFilterFunction<ServerResponse, ServerResponse>> filterFunctions = new ArrayList<>();
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -50,13 +51,23 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return this;
|
||||
}
|
||||
|
||||
private RouterFunctions.Builder add(RequestPredicate predicate,
|
||||
HandlerFunction<ServerResponse> handlerFunction) {
|
||||
|
||||
private RouterFunctions.Builder add(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
this.routerFunctions.add(RouterFunctions.route(predicate, handlerFunction));
|
||||
return this;
|
||||
}
|
||||
|
||||
// GET
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder GET(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.GET), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder GET(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.GET).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder GET(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.GET(pattern), handlerFunction);
|
||||
|
@ -69,6 +80,18 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.GET(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// HEAD
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder HEAD(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.HEAD), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder HEAD(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.HEAD).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder HEAD(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.HEAD(pattern), handlerFunction);
|
||||
|
@ -81,6 +104,18 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.HEAD(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// POST
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder POST(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.POST), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder POST(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.POST).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder POST(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.POST(pattern), handlerFunction);
|
||||
|
@ -93,6 +128,18 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.POST(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// PUT
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder PUT(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.PUT), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder PUT(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.PUT).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder PUT(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.PUT(pattern), handlerFunction);
|
||||
|
@ -105,6 +152,18 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.PUT(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// PATCH
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder PATCH(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.PATCH), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder PATCH(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.PATCH).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder PATCH(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.PATCH(pattern), handlerFunction);
|
||||
|
@ -117,6 +176,18 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.PATCH(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// DELETE
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder DELETE(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.DELETE), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder DELETE(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.DELETE).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder DELETE(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.DELETE(pattern), handlerFunction);
|
||||
|
@ -129,6 +200,18 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.DELETE(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// OPTIONS
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder OPTIONS(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.OPTIONS), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder OPTIONS(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.OPTIONS).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder OPTIONS(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.OPTIONS(pattern), handlerFunction);
|
||||
|
@ -141,6 +224,8 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.OPTIONS(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// other
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder route(RequestPredicate predicate,
|
||||
HandlerFunction<ServerResponse> handlerFunction) {
|
||||
|
|
|
@ -276,6 +276,7 @@ public abstract class RouterFunctions {
|
|||
return routerFunction;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Represents a discoverable builder for router functions.
|
||||
* Obtained via {@link RouterFunctions#route()}.
|
||||
|
@ -283,6 +284,14 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
public interface Builder {
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code GET} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code GET} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder GET(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code GET} requests
|
||||
* that match the given pattern.
|
||||
|
@ -293,6 +302,18 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder GET(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code GET} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code GET} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder GET(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code GET} requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -307,12 +328,20 @@ public abstract class RouterFunctions {
|
|||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code GET} requests that
|
||||
* match {@code pattern}
|
||||
* match {@code pattern} and the predicate
|
||||
* @return this builder
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder GET(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code HEAD} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code HEAD} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder HEAD(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code HEAD} requests
|
||||
* that match the given pattern.
|
||||
|
@ -323,6 +352,18 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder HEAD(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code HEAD} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code HEAD} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder HEAD(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code HEAD} requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -334,6 +375,14 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder HEAD(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code POST} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code POST} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder POST(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code POST} requests
|
||||
* that match the given pattern.
|
||||
|
@ -344,6 +393,18 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder POST(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code POST} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code POST} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder POST(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code POST} requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -363,6 +424,14 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder POST(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code PUT} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code PUT} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder PUT(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code PUT} requests
|
||||
* that match the given pattern.
|
||||
|
@ -373,6 +442,18 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder PUT(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code PUT} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code PUT} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder PUT(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code PUT} requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -392,6 +473,14 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder PUT(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code PATCH} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code PATCH} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder PATCH(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code PATCH} requests
|
||||
* that match the given pattern.
|
||||
|
@ -402,6 +491,18 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder PATCH(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code PATCH} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code PATCH} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder PATCH(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code PATCH} requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -421,6 +522,14 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder PATCH(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code DELETE} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code DELETE} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder DELETE(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code DELETE} requests
|
||||
* that match the given pattern.
|
||||
|
@ -431,6 +540,18 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder DELETE(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code DELETE} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code DELETE} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder DELETE(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code DELETE} requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -442,6 +563,14 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder DELETE(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code OPTIONS} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code OPTIONS} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder OPTIONS(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code OPTIONS} requests
|
||||
* that match the given pattern.
|
||||
|
@ -452,6 +581,18 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder OPTIONS(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code OPTIONS} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code OPTIONS} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder OPTIONS(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code OPTIONS} requests
|
||||
* that match the given pattern and predicate.
|
||||
|
|
|
@ -58,6 +58,7 @@ fun router(routes: RouterFunctionDsl.() -> Unit) = RouterFunctionDsl(routes).bui
|
|||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @author Yevhenii Melnyk
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.0
|
||||
*/
|
||||
class RouterFunctionDsl internal constructor (private val init: RouterFunctionDsl.() -> Unit) {
|
||||
|
@ -148,6 +149,14 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
builder.path(this, Supplier { RouterFunctionDsl(init).build() })
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `GET` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun GET(f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.GET { f(it).cast(ServerResponse::class.java) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `GET` requests
|
||||
* that match the given pattern.
|
||||
|
@ -157,6 +166,16 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
builder.GET(pattern) { f(it).cast(ServerResponse::class.java) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `GET` requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun GET(predicate: RequestPredicate, f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.GET(predicate, HandlerFunction<ServerResponse> { f(it).cast(ServerResponse::class.java) })
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `GET` requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -170,11 +189,19 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
|
||||
/**
|
||||
* Return a [RequestPredicate] that matches if request's HTTP method is `GET`
|
||||
* and the given [pattern] matches against the request path.
|
||||
* and the given `pattern` matches against the request path.
|
||||
* @see RequestPredicates.GET
|
||||
*/
|
||||
fun GET(pattern: String): RequestPredicate = RequestPredicates.GET(pattern)
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `HEAD` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun HEAD(f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.HEAD { f(it).cast(ServerResponse::class.java) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `HEAD` requests
|
||||
* that match the given pattern.
|
||||
|
@ -186,7 +213,17 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `HEAD` requests
|
||||
* that match the given pattern.
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun HEAD(predicate: RequestPredicate, f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.HEAD(predicate, HandlerFunction<ServerResponse> { f(it).cast(ServerResponse::class.java) })
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `HEAD` requests
|
||||
* that match the given pattern and predicate.
|
||||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @since 5.2
|
||||
|
@ -202,6 +239,14 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
*/
|
||||
fun HEAD(pattern: String): RequestPredicate = RequestPredicates.HEAD(pattern)
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `POST` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun POST(f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.POST { f(it).cast(ServerResponse::class.java) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `POST` requests
|
||||
* that match the given pattern.
|
||||
|
@ -213,7 +258,17 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `POST` requests
|
||||
* that match the given pattern.
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun POST(predicate: RequestPredicate, f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.POST(predicate, HandlerFunction<ServerResponse> { f(it).cast(ServerResponse::class.java) })
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `POST` requests
|
||||
* that match the given pattern and predicate.
|
||||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @since 5.2
|
||||
|
@ -229,6 +284,14 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
*/
|
||||
fun POST(pattern: String): RequestPredicate = RequestPredicates.POST(pattern)
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PUT` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun PUT(f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.PUT { f(it).cast(ServerResponse::class.java) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PUT` requests
|
||||
* that match the given pattern.
|
||||
|
@ -240,7 +303,17 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PUT` requests
|
||||
* that match the given pattern.
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun PUT(predicate: RequestPredicate, f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.PUT(predicate, HandlerFunction<ServerResponse> { f(it).cast(ServerResponse::class.java) })
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PUT` requests
|
||||
* that match the given pattern and predicate.
|
||||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @since 5.2
|
||||
|
@ -256,15 +329,33 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
*/
|
||||
fun PUT(pattern: String): RequestPredicate = RequestPredicates.PUT(pattern)
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PATCH` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun PATCH(f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.PATCH { f(it).cast(ServerResponse::class.java) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PATCH` requests
|
||||
* that match the given pattern and predicate.
|
||||
* that match the given pattern.
|
||||
* @param pattern the pattern to match to
|
||||
*/
|
||||
fun PATCH(pattern: String, f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.PATCH(pattern) { f(it).cast(ServerResponse::class.java) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PATCH` requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun PATCH(predicate: RequestPredicate, f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.PATCH(predicate, HandlerFunction<ServerResponse> { f(it).cast(ServerResponse::class.java) })
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PATCH` requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -280,11 +371,19 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
* Return a [RequestPredicate] that matches if request's HTTP method is `PATCH`
|
||||
* and the given `pattern` matches against the request path.
|
||||
* @param pattern the path pattern to match against
|
||||
* @return a predicate that matches if the request method is PATCH and if the given pattern
|
||||
* @return a predicate that matches if the request method is `PATCH` and if the given pattern
|
||||
* matches against the request path
|
||||
*/
|
||||
fun PATCH(pattern: String): RequestPredicate = RequestPredicates.PATCH(pattern)
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `DELETE` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun DELETE(f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.DELETE { f(it).cast(ServerResponse::class.java) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `DELETE` requests
|
||||
* that match the given pattern.
|
||||
|
@ -296,7 +395,17 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `DELETE` requests
|
||||
* that match the given pattern.
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun DELETE(predicate: RequestPredicate, f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.DELETE(predicate, HandlerFunction<ServerResponse> { f(it).cast(ServerResponse::class.java) })
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `DELETE` requests
|
||||
* that match the given pattern and predicate.
|
||||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @since 5.2
|
||||
|
@ -309,11 +418,19 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
* Return a [RequestPredicate] that matches if request's HTTP method is `DELETE`
|
||||
* and the given `pattern` matches against the request path.
|
||||
* @param pattern the path pattern to match against
|
||||
* @return a predicate that matches if the request method is DELETE and if the given pattern
|
||||
* @return a predicate that matches if the request method is `DELETE` and if the given pattern
|
||||
* matches against the request path
|
||||
*/
|
||||
fun DELETE(pattern: String): RequestPredicate = RequestPredicates.DELETE(pattern)
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `OPTIONS` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun OPTIONS(f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.OPTIONS { f(it).cast(ServerResponse::class.java) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `OPTIONS` requests
|
||||
* that match the given pattern.
|
||||
|
@ -325,7 +442,17 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `OPTIONS` requests
|
||||
* that match the given pattern.
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun OPTIONS(predicate: RequestPredicate, f: (ServerRequest) -> Mono<out ServerResponse>) {
|
||||
builder.OPTIONS(predicate, HandlerFunction<ServerResponse> { f(it).cast(ServerResponse::class.java) })
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `OPTIONS` requests
|
||||
* that match the given pattern and predicate.
|
||||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @since 5.2
|
||||
|
@ -338,7 +465,7 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
|||
* Return a [RequestPredicate] that matches if request's HTTP method is `OPTIONS`
|
||||
* and the given `pattern` matches against the request path.
|
||||
* @param pattern the path pattern to match against
|
||||
* @return a predicate that matches if the request method is OPTIONS and if the given pattern
|
||||
* @return a predicate that matches if the request method is `OPTIONS` and if the given pattern
|
||||
* matches against the request path
|
||||
*/
|
||||
fun OPTIONS(pattern: String): RequestPredicate = RequestPredicates.OPTIONS(pattern)
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.function.Predicate;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
@ -36,9 +37,9 @@ import org.springframework.util.Assert;
|
|||
*/
|
||||
class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
|
||||
private List<RouterFunction<ServerResponse>> routerFunctions = new ArrayList<>();
|
||||
private final List<RouterFunction<ServerResponse>> routerFunctions = new ArrayList<>();
|
||||
|
||||
private List<HandlerFilterFunction<ServerResponse, ServerResponse>> filterFunctions = new ArrayList<>();
|
||||
private final List<HandlerFilterFunction<ServerResponse, ServerResponse>> filterFunctions = new ArrayList<>();
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -48,13 +49,23 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return this;
|
||||
}
|
||||
|
||||
private RouterFunctions.Builder add(RequestPredicate predicate,
|
||||
HandlerFunction<ServerResponse> handlerFunction) {
|
||||
|
||||
private RouterFunctions.Builder add(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
this.routerFunctions.add(RouterFunctions.route(predicate, handlerFunction));
|
||||
return this;
|
||||
}
|
||||
|
||||
// GET
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder GET(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.GET), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder GET(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.GET).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder GET(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.GET(pattern), handlerFunction);
|
||||
|
@ -67,6 +78,18 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.GET(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// HEAD
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder HEAD(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.HEAD), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder HEAD(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.HEAD).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder HEAD(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.HEAD(pattern), handlerFunction);
|
||||
|
@ -79,6 +102,18 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.HEAD(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// POST
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder POST(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.POST), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder POST(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.POST).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder POST(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.POST(pattern), handlerFunction);
|
||||
|
@ -91,6 +126,18 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.POST(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// PUT
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder PUT(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.PUT), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder PUT(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.PUT).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder PUT(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.PUT(pattern), handlerFunction);
|
||||
|
@ -103,6 +150,18 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.PUT(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// PATCH
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder PATCH(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.PATCH), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder PATCH(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.PATCH).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder PATCH(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.PATCH(pattern), handlerFunction);
|
||||
|
@ -115,6 +174,18 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.PATCH(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// DELETE
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder DELETE(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.DELETE), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder DELETE(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.DELETE).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder DELETE(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.DELETE(pattern), handlerFunction);
|
||||
|
@ -127,15 +198,21 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.DELETE(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// OPTIONS
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder OPTIONS(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.OPTIONS(pattern), handlerFunction);
|
||||
public RouterFunctions.Builder OPTIONS(HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.OPTIONS), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder route(RequestPredicate predicate,
|
||||
HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RouterFunctions.route(predicate, handlerFunction));
|
||||
public RouterFunctions.Builder OPTIONS(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.method(HttpMethod.OPTIONS).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder OPTIONS(String pattern, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RequestPredicates.OPTIONS(pattern), handlerFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -145,6 +222,14 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
|||
return add(RequestPredicates.OPTIONS(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
// other
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder route(RequestPredicate predicate,
|
||||
HandlerFunction<ServerResponse> handlerFunction) {
|
||||
return add(RouterFunctions.route(predicate, handlerFunction));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder resources(String pattern, Resource location) {
|
||||
return add(RouterFunctions.resources(pattern, location));
|
||||
|
|
|
@ -196,6 +196,14 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
public interface Builder {
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code GET} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code GET} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder GET(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code GET} requests
|
||||
* that match the given pattern.
|
||||
|
@ -206,6 +214,18 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder GET(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code GET} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code GET} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder GET(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code GET} requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -220,12 +240,20 @@ public abstract class RouterFunctions {
|
|||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code GET} requests that
|
||||
* match {@code pattern}
|
||||
* match {@code pattern} and the predicate
|
||||
* @return this builder
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder GET(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code HEAD} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code HEAD} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder HEAD(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code HEAD} requests
|
||||
* that match the given pattern.
|
||||
|
@ -236,6 +264,18 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder HEAD(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code HEAD} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code HEAD} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder HEAD(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code HEAD} requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -247,6 +287,14 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder HEAD(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code POST} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code POST} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder POST(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code POST} requests
|
||||
* that match the given pattern.
|
||||
|
@ -257,6 +305,18 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder POST(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code POST} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code POST} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder POST(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code POST} requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -276,6 +336,14 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder POST(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code PUT} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code PUT} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder PUT(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code PUT} requests
|
||||
* that match the given pattern.
|
||||
|
@ -286,6 +354,18 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder PUT(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code PUT} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code PUT} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder PUT(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code PUT} requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -305,6 +385,14 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder PUT(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code PATCH} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code PATCH} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder PATCH(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code PATCH} requests
|
||||
* that match the given pattern.
|
||||
|
@ -315,6 +403,18 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder PATCH(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code PATCH} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code PATCH} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder PATCH(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code PATCH} requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -334,6 +434,14 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder PATCH(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code DELETE} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code DELETE} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder DELETE(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code DELETE} requests
|
||||
* that match the given pattern.
|
||||
|
@ -344,6 +452,18 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder DELETE(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code DELETE} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code DELETE} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder DELETE(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code DELETE} requests
|
||||
* that match the given pattern and predicate.
|
||||
|
@ -355,6 +475,14 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder DELETE(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles HTTP {@code OPTIONS} requests.
|
||||
* @param handlerFunction the handler function to handle all {@code OPTIONS} requests
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
*/
|
||||
Builder OPTIONS(HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code OPTIONS} requests
|
||||
* that match the given pattern.
|
||||
|
@ -366,15 +494,16 @@ public abstract class RouterFunctions {
|
|||
Builder OPTIONS(String pattern, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all requests that match the
|
||||
* given predicate.
|
||||
*
|
||||
* @param predicate the request predicate to match
|
||||
* @param handlerFunction the handler function to handle all requests that match the predicate
|
||||
* Adds a route to the given handler function that handles all HTTP {@code OPTIONS} requests
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @param handlerFunction the handler function to handle all {@code OPTIONS} requests that
|
||||
* match {@code predicate}
|
||||
* @return this builder
|
||||
* @since 5.3
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder route(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
Builder OPTIONS(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP {@code OPTIONS} requests
|
||||
|
@ -387,6 +516,16 @@ public abstract class RouterFunctions {
|
|||
*/
|
||||
Builder OPTIONS(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all requests that match the
|
||||
* given predicate.
|
||||
* @param predicate the request predicate to match
|
||||
* @param handlerFunction the handler function to handle all requests that match the predicate
|
||||
* @return this builder
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
Builder route(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction);
|
||||
|
||||
/**
|
||||
* Adds the given route to this builder. Can be used to merge externally defined router
|
||||
* functions into this builder, or can be combined with
|
||||
|
|
|
@ -48,6 +48,7 @@ import java.util.function.Supplier
|
|||
* }
|
||||
* ```
|
||||
* @author Sebastien Deleuze
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.2
|
||||
*/
|
||||
fun router(routes: (RouterFunctionDsl.() -> Unit)) = RouterFunctionDsl(routes).build()
|
||||
|
@ -134,7 +135,6 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
builder.nest(this, Supplier(RouterFunctionDsl(r)::build))
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Route to the given router function if the given request predicate (String
|
||||
* processed as a path predicate) applies. This method can be used to create
|
||||
|
@ -145,6 +145,14 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
*/
|
||||
fun String.nest(r: (RouterFunctionDsl.() -> Unit)) = path(this).nest(r)
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `GET` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun GET(f: (ServerRequest) -> ServerResponse) {
|
||||
builder.GET(HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `GET` requests
|
||||
* that match the given pattern.
|
||||
|
@ -156,7 +164,17 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `GET` requests
|
||||
* that match the given pattern.
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun GET(predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse) {
|
||||
builder.GET(predicate, HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `GET` requests
|
||||
* that match the given pattern and predicate.
|
||||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @since 5.2
|
||||
|
@ -172,6 +190,14 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
*/
|
||||
fun GET(pattern: String): RequestPredicate = RequestPredicates.GET(pattern)
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `HEAD` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun HEAD(f: (ServerRequest) -> ServerResponse) {
|
||||
builder.HEAD(HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `HEAD` requests
|
||||
* that match the given pattern.
|
||||
|
@ -183,7 +209,17 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `HEAD` requests
|
||||
* that match the given pattern.
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun HEAD(predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse) {
|
||||
builder.HEAD(predicate, HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `HEAD` requests
|
||||
* that match the given pattern and predicate.
|
||||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @since 5.2
|
||||
|
@ -199,6 +235,14 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
*/
|
||||
fun HEAD(pattern: String): RequestPredicate = RequestPredicates.HEAD(pattern)
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `POST` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun POST(f: (ServerRequest) -> ServerResponse) {
|
||||
builder.POST(HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `POST` requests
|
||||
* that match the given pattern.
|
||||
|
@ -210,7 +254,17 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `POST` requests
|
||||
* that match the given pattern.
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun POST(predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse) {
|
||||
builder.POST(predicate, HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `POST` requests
|
||||
* that match the given pattern and predicate.
|
||||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @since 5.2
|
||||
|
@ -226,6 +280,14 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
*/
|
||||
fun POST(pattern: String): RequestPredicate = RequestPredicates.POST(pattern)
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PUT` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun PUT(f: (ServerRequest) -> ServerResponse) {
|
||||
builder.PUT(HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PUT` requests
|
||||
* that match the given pattern.
|
||||
|
@ -237,7 +299,17 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PUT` requests
|
||||
* that match the given pattern.
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun PUT(predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse) {
|
||||
builder.PUT(predicate, HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PUT` requests
|
||||
* that match the given pattern and predicate.
|
||||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @since 5.2
|
||||
|
@ -253,6 +325,14 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
*/
|
||||
fun PUT(pattern: String): RequestPredicate = RequestPredicates.PUT(pattern)
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PATCH` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun PATCH(f: (ServerRequest) -> ServerResponse) {
|
||||
builder.PATCH(HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PATCH` requests
|
||||
* that match the given pattern.
|
||||
|
@ -264,7 +344,17 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PATCH` requests
|
||||
* that match the given pattern.
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun PATCH(predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse) {
|
||||
builder.PATCH(predicate, HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `PATCH` requests
|
||||
* that match the given pattern and predicate.
|
||||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @since 5.2
|
||||
|
@ -282,6 +372,14 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
*/
|
||||
fun PATCH(pattern: String): RequestPredicate = RequestPredicates.PATCH(pattern)
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `DELETE` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun DELETE(f: (ServerRequest) -> ServerResponse) {
|
||||
builder.DELETE(HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `DELETE` requests
|
||||
* that match the given pattern.
|
||||
|
@ -293,7 +391,17 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `DELETE` requests
|
||||
* that match the given pattern.
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun DELETE(predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse) {
|
||||
builder.DELETE(predicate, HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `DELETE` requests
|
||||
* that match the given pattern and predicate.
|
||||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @since 5.2
|
||||
|
@ -311,6 +419,14 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
*/
|
||||
fun DELETE(pattern: String): RequestPredicate = RequestPredicates.DELETE(pattern)
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `OPTIONS` requests.
|
||||
* @since 5.3
|
||||
*/
|
||||
fun OPTIONS(f: (ServerRequest) -> ServerResponse) {
|
||||
builder.OPTIONS(HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `OPTIONS` requests
|
||||
* that match the given pattern.
|
||||
|
@ -322,7 +438,17 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `OPTIONS` requests
|
||||
* that match the given pattern.
|
||||
* that match the given predicate.
|
||||
* @param predicate predicate to match
|
||||
* @since 5.3
|
||||
*/
|
||||
fun OPTIONS(predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse) {
|
||||
builder.OPTIONS(predicate, HandlerFunction(f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route to the given handler function that handles all HTTP `OPTIONS` requests
|
||||
* that match the given pattern and predicate.
|
||||
* @param pattern the pattern to match to
|
||||
* @param predicate additional predicate to match
|
||||
* @since 5.2
|
||||
|
@ -654,4 +780,4 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
|||
* Equivalent to [RouterFunction.and].
|
||||
*/
|
||||
operator fun <T: ServerResponse> RouterFunction<T>.plus(other: RouterFunction<T>) =
|
||||
this.and(other)
|
||||
this.and(other)
|
||||
|
|
|
@ -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())) {
|
||||
|
|
Loading…
Reference in New Issue