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:
Arjen Poutsma
2020-10-06 11:00:17 +02:00
parent d3087537d5
commit 200b33b26a
8 changed files with 757 additions and 54 deletions

View File

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

View File

@@ -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.

View File

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