RouterFunctionDsl

Provide a WebMvc.fn RouterFunction Kotlin DSL created by router { } in order to be able to write idiomatic Kotlin code.

Author

Sebastien Deleuze

Since

5.2

Functions

Link copied to clipboard
fun accept(vararg mediaType: MediaType): RequestPredicate

Return a RequestPredicate that tests if the request's accept } header is compatible with any of the given media types.

fun accept(mediaType: MediaType, f: (ServerRequest) -> ServerResponse)

Route to the given handler function if the given accept predicate applies.

Link copied to clipboard
Link copied to clipboard
fun add(routerFunction: RouterFunction<ServerResponse>)

Merge externally defined router functions into this one.

Link copied to clipboard
fun after(responseProcessor: (ServerRequest, ServerResponse) -> ServerResponse)

Filter the response object for all routes created by this builder with the given response processing function. Filters are typically used to address cross-cutting concerns, such as logging, security, etc.

Link copied to clipboard

Return a composed request predicate that tests against both this predicate (String processed as a path predicate) AND the other predicate. When evaluating the composed predicate, if this predicate is false, then the other predicate is not evaluated.

Return a composed request predicate that tests against both this predicate AND the other predicate (String processed as a path predicate). When evaluating the composed predicate, if this predicate is false, then the other predicate is not evaluated.

Return a composed request predicate that tests against both this predicate AND the other predicate. When evaluating the composed predicate, if this predicate is false, then the other predicate is not evaluated.

Link copied to clipboard
Link copied to clipboard
fun before(requestProcessor: (ServerRequest) -> ServerRequest)

Filter the request object for all routes created by this builder with the given request processing function. Filters are typically used to address cross-cutting concerns, such as logging, security, etc.

Link copied to clipboard
fun contentType(vararg mediaTypes: MediaType): RequestPredicate

Return a RequestPredicate that tests if the request's content type is included by any of the given media types.

fun contentType(mediaType: MediaType, f: (ServerRequest) -> ServerResponse)

Route to the given handler function if the given contentType predicate applies.

Link copied to clipboard
Link copied to clipboard

Adds a route to the given handler function that handles all HTTP DELETE requests.

Return a RequestPredicate that matches if request's HTTP method is DELETE and the given pattern matches against the request path.

fun DELETE(pattern: String, f: (ServerRequest) -> ServerResponse)

Adds a route to the given handler function that handles all HTTP DELETE requests that match the given pattern.

Adds a route to the given handler function that handles all HTTP DELETE requests that match the given predicate.

fun DELETE(pattern: String, predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse)

Adds a route to the given handler function that handles all HTTP DELETE requests that match the given pattern and predicate.

Link copied to clipboard

Filters all routes created by this router with the given filter function. Filter functions are typically used to address cross-cutting concerns, such as logging, security, etc.

Link copied to clipboard
Link copied to clipboard

Adds a route to the given handler function that handles all HTTP GET requests.

fun GET(pattern: String): RequestPredicate

Return a RequestPredicate that matches if request's HTTP method is GET and the given pattern matches against the request path.

fun GET(pattern: String, f: (ServerRequest) -> ServerResponse)

Adds a route to the given handler function that handles all HTTP GET requests that match the given pattern.

Adds a route to the given handler function that handles all HTTP GET requests that match the given predicate.

fun GET(pattern: String, predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse)

Adds a route to the given handler function that handles all HTTP GET requests that match the given pattern and predicate.

Link copied to clipboard

Adds a route to the given handler function that handles all HTTP HEAD requests.

Return a RequestPredicate that matches if request's HTTP method is HEAD and the given pattern matches against the request path.

fun HEAD(pattern: String, f: (ServerRequest) -> ServerResponse)

Adds a route to the given handler function that handles all HTTP HEAD requests that match the given pattern.

Adds a route to the given handler function that handles all HTTP HEAD requests that match the given predicate.

fun HEAD(pattern: String, predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse)

Adds a route to the given handler function that handles all HTTP HEAD requests that match the given pattern and predicate.

Link copied to clipboard

Return a RequestPredicate that tests the request's headers against the given headers predicate.

Route to the given handler function if the given headers predicate applies.

Link copied to clipboard

Route to the given handler function if the given predicate (String processed as a path predicate) applies.

Route to the given handler function if the given request predicate applies.

Link copied to clipboard
fun method(httpMethod: HttpMethod): RequestPredicate

Return a RequestPredicate that tests against the given HTTP method.

fun method(httpMethod: HttpMethod, f: (ServerRequest) -> ServerResponse)

Route to the given handler function if the given method predicate applies.

Link copied to clipboard

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 nested routes, where a group of routes share a common path (prefix), header, or other request predicate.

Route to the given router function if the given request predicate applies. This method can be used to create nested routes, where a group of routes share a common path (prefix), header, or other request predicate.

Link copied to clipboard
Link copied to clipboard

Return a predicate that represents the logical negation of this predicate.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
inline fun <E : Throwable> onError(noinline responseProvider: (Throwable, ServerRequest) -> ServerResponse)
fun onError(predicate: (Throwable) -> Boolean, responseProvider: (Throwable, ServerRequest) -> ServerResponse)

Filters all exceptions that match the predicate by applying the given response provider function.

Link copied to clipboard

Adds a route to the given handler function that handles all HTTP OPTIONS requests.

Return a RequestPredicate that matches if request's HTTP method is OPTIONS and the given pattern matches against the request path.

Adds a route to the given handler function that handles all HTTP OPTIONS requests that match the given pattern.

Adds a route to the given handler function that handles all HTTP OPTIONS requests that match the given predicate.

fun OPTIONS(pattern: String, predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse)

Adds a route to the given handler function that handles all HTTP OPTIONS requests that match the given pattern and predicate.

Link copied to clipboard

Return a composed request predicate that tests against both this predicate (String processed as a path predicate) OR the other predicate. When evaluating the composed predicate, if this predicate is true, then the other predicate is not evaluated.

Return a composed request predicate that tests against both this predicate OR the other predicate (String processed as a path predicate). When evaluating the composed predicate, if this predicate is true, then the other predicate is not evaluated.

Return a composed request predicate that tests against both this predicate OR the other predicate. When evaluating the composed predicate, if this predicate is true, then the other predicate is not evaluated.

Link copied to clipboard
fun param(name: String, predicate: (String) -> Boolean): RequestPredicate

Return a RequestPredicate that tests the request's query parameter of the given name against the given predicate.

fun param(name: String, predicate: (String) -> Boolean, f: (ServerRequest) -> ServerResponse)

Route to the given handler function if the given queryParam predicate applies.

Link copied to clipboard

Adds a route to the given handler function that handles all HTTP PATCH requests.

Return a RequestPredicate that matches if request's HTTP method is PATCH and the given pattern matches against the request path.

fun PATCH(pattern: String, f: (ServerRequest) -> ServerResponse)

Adds a route to the given handler function that handles all HTTP PATCH requests that match the given pattern.

Adds a route to the given handler function that handles all HTTP PATCH requests that match the given predicate.

fun PATCH(pattern: String, predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse)

Adds a route to the given handler function that handles all HTTP PATCH requests that match the given pattern and predicate.

Link copied to clipboard

Return a RequestPredicate that tests the request path against the given path pattern.

fun path(pattern: String, f: (ServerRequest) -> ServerResponse)

Route to the given handler function if the given path predicate applies.

Link copied to clipboard

Return a RequestPredicate that matches if the request's path matches the given predicate.

Return a RequestPredicate that matches if the request's path has the given extension.

Route to the given handler function if the given pathExtension predicate applies.

Link copied to clipboard
Link copied to clipboard

Adds a route to the given handler function that handles all HTTP POST requests.

Return a RequestPredicate that matches if request's HTTP method is POST and the given pattern matches against the request path.

fun POST(pattern: String, f: (ServerRequest) -> ServerResponse)

Adds a route to the given handler function that handles all HTTP POST requests that match the given pattern.

Adds a route to the given handler function that handles all HTTP POST requests that match the given predicate.

fun POST(pattern: String, predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse)

Adds a route to the given handler function that handles all HTTP POST requests that match the given pattern and predicate.

Link copied to clipboard

Adds a route to the given handler function that handles all HTTP PUT requests.

fun PUT(pattern: String): RequestPredicate

Return a RequestPredicate that matches if request's HTTP method is PUT and the given pattern matches against the request path.

fun PUT(pattern: String, f: (ServerRequest) -> ServerResponse)

Adds a route to the given handler function that handles all HTTP PUT requests that match the given pattern.

Adds a route to the given handler function that handles all HTTP PUT requests that match the given predicate.

fun PUT(pattern: String, predicate: RequestPredicate, f: (ServerRequest) -> ServerResponse)

Adds a route to the given handler function that handles all HTTP PUT requests that match the given pattern and predicate.

Link copied to clipboard
fun resource(predicate: RequestPredicate, resource: Resource)

Route requests that match the given predicate to the given resource.

Link copied to clipboard
fun resources(lookupFunction: (ServerRequest) -> Resource?)

Route to resources using the provided lookup function. If the lookup function provides a Resource for the given request, it will be it will be exposed using a HandlerFunction that handles GET, HEAD, and OPTIONS requests.

fun resources(path: String, location: Resource)

Route requests that match the given pattern to resources relative to the given root location.

Link copied to clipboard
Link copied to clipboard
fun status(status: HttpStatusCode): ServerResponse.BodyBuilder
Link copied to clipboard
Link copied to clipboard
fun withAttribute(name: String, value: Any)

Add an attribute with the given name and value to the last route built with this builder.

Link copied to clipboard
fun withAttributes(attributesConsumer: (MutableMap<String, Any>) -> Unit)

Manipulate the attributes of the last route built with the given consumer.