spring-framework / org.springframework.web.reactive.function.server / RouterFunctionDsl

RouterFunctionDsl

class RouterFunctionDsl

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

Author
Sebastien Deleuze

Author
Yevhenii Melnyk

Since
5.0

Constructors

<init>

RouterFunctionDsl(init: RouterFunctionDsl.() -> Unit)

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

Functions

accept

fun accept(mediaType: MediaType, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun accept(mediaType: MediaType): RequestPredicate

Return a {@code RequestPredicate} that tests if the request's {@linkplain ServerRequest.Headers#accept() accept} header is {@linkplain MediaType#isCompatibleWith(MediaType) compatible} with any of the given media types.

accepted

fun accepted(): BodyBuilder

Create a builder with an 202 Accepted status.

and

infix fun RequestPredicate.and(other: String): RequestPredicate

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.

infix fun String.and(other: RequestPredicate): RequestPredicate

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.

infix fun RequestPredicate.and(other: RequestPredicate): RequestPredicate

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.

badRequest

fun badRequest(): BodyBuilder

Create a builder with a 400 Bad Request status.

contentType

fun contentType(mediaType: MediaType, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun contentType(mediaType: MediaType): RequestPredicate

Return a {@code RequestPredicate} that tests if the request's {@linkplain ServerRequest.Headers#contentType() content type} is {@linkplain MediaType#includes(MediaType) included} by any of the given media types.

created

fun created(location: URI): BodyBuilder

Create a new builder with a 201 Created status and a location header set to the given URI.

DELETE

fun DELETE(pattern: String, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun DELETE(pattern: String): RequestPredicate

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

from

fun from(other: ServerResponse): BodyBuilder

Create a builder with the status code and headers of the given response.

GET

fun GET(pattern: String, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun GET(pattern: String): RequestPredicate

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

HEAD

fun HEAD(pattern: String, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun HEAD(pattern: String): RequestPredicate

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

headers

fun headers(headersPredicate: (Headers) -> Boolean, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun headers(headersPredicate: (Headers) -> Boolean): RequestPredicate

Return a {@code RequestPredicate} that tests the request's headers against the given headers predicate.

invoke

operator fun RequestPredicate.invoke(f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

operator fun String.invoke(f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

method

fun method(httpMethod: HttpMethod, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun method(httpMethod: HttpMethod): RequestPredicate

Return a {@code RequestPredicate} that tests against the given HTTP method.

nest

fun RequestPredicate.nest(init: RouterFunctionDsl.() -> Unit): Unit

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.

fun String.nest(init: RouterFunctionDsl.() -> Unit): Unit

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.

noContent

fun noContent(): HeadersBuilder<*>

Create a builder with a 204 No Content status.

not

operator fun RequestPredicate.not(): RequestPredicate

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

notFound

fun notFound(): HeadersBuilder<*>

Create a builder with a 404 Not Found status.

ok

fun ok(): BodyBuilder

Create a builder with the status set to 200 OK.

OPTIONS

fun OPTIONS(pattern: String, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun OPTIONS(pattern: String): RequestPredicate

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

or

infix fun RequestPredicate.or(other: String): RequestPredicate

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.

infix fun String.or(other: RequestPredicate): RequestPredicate

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.

infix fun RequestPredicate.or(other: RequestPredicate): RequestPredicate

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.

PATCH

fun PATCH(pattern: String, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun PATCH(pattern: String): RequestPredicate

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

path

fun path(pattern: String, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun path(pattern: String): RequestPredicate

Return a {@code RequestPredicate} that tests the request path against the given path pattern.

pathExtension

fun pathExtension(extension: String, f: (ServerRequest) -> Mono<out ServerResponse>): Unit
fun pathExtension(predicate: (String) -> Boolean, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun pathExtension(extension: String): RequestPredicate

Return a {@code RequestPredicate} that matches if the request's path has the given extension.

fun pathExtension(predicate: (String) -> Boolean): RequestPredicate

Return a {@code RequestPredicate} that matches if the request's path matches the given predicate.

permanentRedirect

fun permanentRedirect(location: URI): BodyBuilder

Create a builder with a 308 Permanent Redirect status and a location header set to the given URI.

POST

fun POST(pattern: String, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun POST(pattern: String): RequestPredicate

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

PUT

fun PUT(pattern: String, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun PUT(pattern: String): RequestPredicate

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

queryParam

fun queryParam(name: String, predicate: (String) -> Boolean, f: (ServerRequest) -> Mono<out ServerResponse>): Unit

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

fun queryParam(name: String, predicate: (String) -> Boolean): RequestPredicate

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

resources

fun resources(path: String, location: Resource): Unit

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

fun resources(lookupFunction: (ServerRequest) -> Mono<Resource>): Unit

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.

seeOther

fun seeOther(location: URI): BodyBuilder

Create a builder with a 303 See Other status and a location header set to the given URI.

status

fun status(status: HttpStatus): BodyBuilder
fun status(status: Int): BodyBuilder

Create a builder with the given HTTP status.

temporaryRedirect

fun temporaryRedirect(location: URI): BodyBuilder

Create a builder with a 307 Temporary Redirect status and a location header set to the given URI.

unprocessableEntity

fun unprocessableEntity(): BodyBuilder

Create a builder with an 422 Unprocessable Entity status.