Skip to content

Commit

Permalink
Improve parity between Java and Kotlin router DSL
Browse files Browse the repository at this point in the history
This commit adds variants with pattern + predicate to
Kotlin router DSLs, and vararg where necessary.

Closes gh-23524
  • Loading branch information
sdeleuze committed Sep 16, 2019
1 parent 848804a commit 5a0216d
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 95 deletions.
Expand Up @@ -149,13 +149,25 @@ class CoRouterFunctionDsl(private val init: (CoRouterFunctionDsl.() -> Unit)) {
fun String.nest(r: (CoRouterFunctionDsl.() -> Unit)) = path(this).nest(r)

/**
* Route to the given handler function if the given request predicate applies.
* @see RouterFunctions.route
* Adds a route to the given handler function that handles all HTTP `GET` requests
* that match the given pattern.
* @param pattern the pattern to match to
*/
fun GET(pattern: String, f: suspend (ServerRequest) -> ServerResponse) {
builder.GET(pattern, asHandlerFunction(f))
}

/**
* Adds a route to the given handler function that handles all HTTP `GET` requests
* that match the given pattern.
* @param pattern the pattern to match to
* @param predicate additional predicate to match
* @since 5.2
*/
fun GET(pattern: String, predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) {
builder.GET(pattern, predicate, asHandlerFunction(f))
}

/**
* Return a [RequestPredicate] that matches if request's HTTP method is `GET`
* and the given `pattern` matches against the request path.
Expand All @@ -164,13 +176,25 @@ class CoRouterFunctionDsl(private val init: (CoRouterFunctionDsl.() -> Unit)) {
fun GET(pattern: String): RequestPredicate = RequestPredicates.GET(pattern)

/**
* Route to the given handler function if the given request predicate applies.
* @see RouterFunctions.route
* Adds a route to the given handler function that handles all HTTP `HEAD` requests
* that match the given pattern.
* @param pattern the pattern to match to
*/
fun HEAD(pattern: String, f: suspend (ServerRequest) -> ServerResponse) {
builder.HEAD(pattern, asHandlerFunction(f))
}

/**
* Adds a route to the given handler function that handles all HTTP `HEAD` requests
* that match the given pattern.
* @param pattern the pattern to match to
* @param predicate additional predicate to match
* @since 5.2
*/
fun HEAD(pattern: String, predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) {
builder.HEAD(pattern, predicate, asHandlerFunction(f))
}

/**
* Return a [RequestPredicate] that matches if request's HTTP method is `HEAD`
* and the given `pattern` matches against the request path.
Expand All @@ -179,13 +203,25 @@ class CoRouterFunctionDsl(private val init: (CoRouterFunctionDsl.() -> Unit)) {
fun HEAD(pattern: String): RequestPredicate = RequestPredicates.HEAD(pattern)

/**
* Route to the given handler function if the given `POST` predicate applies.
* @see RouterFunctions.route
* Adds a route to the given handler function that handles all HTTP `POST` requests
* that match the given pattern.
* @param pattern the pattern to match to
*/
fun POST(pattern: String, f: suspend (ServerRequest) -> ServerResponse) {
builder.POST(pattern, asHandlerFunction(f))
}

/**
* Adds a route to the given handler function that handles all HTTP `POST` requests
* that match the given pattern.
* @param pattern the pattern to match to
* @param predicate additional predicate to match
* @since 5.2
*/
fun POST(pattern: String, predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) {
builder.POST(pattern, predicate, asHandlerFunction(f))
}

/**
* Return a [RequestPredicate] that matches if request's HTTP method is `POST`
* and the given `pattern` matches against the request path.
Expand All @@ -194,13 +230,25 @@ class CoRouterFunctionDsl(private val init: (CoRouterFunctionDsl.() -> Unit)) {
fun POST(pattern: String): RequestPredicate = RequestPredicates.POST(pattern)

/**
* Route to the given handler function if the given `PUT` predicate applies.
* @see RouterFunctions.route
* Adds a route to the given handler function that handles all HTTP `PUT` requests
* that match the given pattern.
* @param pattern the pattern to match to
*/
fun PUT(pattern: String, f: suspend (ServerRequest) -> ServerResponse) {
builder.PUT(pattern, asHandlerFunction(f))
}

/**
* Adds a route to the given handler function that handles all HTTP `PUT` requests
* that match the given pattern.
* @param pattern the pattern to match to
* @param predicate additional predicate to match
* @since 5.2
*/
fun PUT(pattern: String, predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) {
builder.PUT(pattern, predicate, asHandlerFunction(f))
}

/**
* Return a [RequestPredicate] that matches if request's HTTP method is `PUT`
* and the given `pattern` matches against the request path.
Expand All @@ -209,13 +257,25 @@ class CoRouterFunctionDsl(private val init: (CoRouterFunctionDsl.() -> Unit)) {
fun PUT(pattern: String): RequestPredicate = RequestPredicates.PUT(pattern)

/**
* Route to the given handler function if the given `PATCH` predicate applies.
* @see RouterFunctions.route
* Adds a route to the given handler function that handles all HTTP `PATCH` requests
* that match the given pattern.
* @param pattern the pattern to match to
*/
fun PATCH(pattern: String, f: suspend (ServerRequest) -> ServerResponse) {
builder.PATCH(pattern, asHandlerFunction(f))
}

/**
* Adds a route to the given handler function that handles all HTTP `PATCH` requests
* that match the given pattern.
* @param pattern the pattern to match to
* @param predicate additional predicate to match
* @since 5.2
*/
fun PATCH(pattern: String, predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) {
builder.PATCH(pattern, predicate, asHandlerFunction(f))
}

/**
* Return a [RequestPredicate] that matches if request's HTTP method is `PATCH`
* and the given `pattern` matches against the request path.
Expand All @@ -226,13 +286,25 @@ class CoRouterFunctionDsl(private val init: (CoRouterFunctionDsl.() -> Unit)) {
fun PATCH(pattern: String): RequestPredicate = RequestPredicates.PATCH(pattern)

/**
* Route to the given handler function if the given `DELETE` predicate applies.
* @see RouterFunctions.route
* Adds a route to the given handler function that handles all HTTP `DELETE` requests
* that match the given pattern.
* @param pattern the pattern to match to
*/
fun DELETE(pattern: String, f: suspend (ServerRequest) -> ServerResponse) {
builder.DELETE(pattern, asHandlerFunction(f))
}

/**
* Adds a route to the given handler function that handles all HTTP `DELETE` requests
* that match the given pattern.
* @param pattern the pattern to match to
* @param predicate additional predicate to match
* @since 5.2
*/
fun DELETE(pattern: String, predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) {
builder.DELETE(pattern, predicate, asHandlerFunction(f))
}

/**
* Return a [RequestPredicate] that matches if request's HTTP method is `DELETE`
* and the given `pattern` matches against the request path.
Expand All @@ -243,13 +315,25 @@ class CoRouterFunctionDsl(private val init: (CoRouterFunctionDsl.() -> Unit)) {
fun DELETE(pattern: String): RequestPredicate = RequestPredicates.DELETE(pattern)

/**
* Route to the given handler function if the given OPTIONS predicate applies.
* @see RouterFunctions.route
* Adds a route to the given handler function that handles all HTTP `OPTIONS` requests
* that match the given pattern.
* @param pattern the pattern to match to
*/
fun OPTIONS(pattern: String, f: suspend (ServerRequest) -> ServerResponse) {
builder.OPTIONS(pattern, asHandlerFunction(f))
}

/**
* Adds a route to the given handler function that handles all HTTP `OPTIONS` requests
* that match the given pattern.
* @param pattern the pattern to match to
* @param predicate additional predicate to match
* @since 5.2
*/
fun OPTIONS(pattern: String, predicate: RequestPredicate, f: suspend (ServerRequest) -> ServerResponse) {
builder.OPTIONS(pattern, predicate, asHandlerFunction(f))
}

/**
* Return a [RequestPredicate] that matches if request's HTTP method is `OPTIONS`
* and the given `pattern` matches against the request path.
Expand Down

0 comments on commit 5a0216d

Please sign in to comment.