Top Description Fields Methods
reactor.netty5.http.server

public Interface HttpServerRoutes

extends BiFunction<HttpServerRequest, HttpServerResponse, Publisher<Void>>
Known Direct Implementers
reactor.netty5.http.server.DefaultHttpServerRoutes
Imports
java.net.URI, java.nio.file.Files, .Path, .Paths, java.util.Comparator, .Objects, java.util.function.BiFunction, .Function, .Predicate, io.netty5.handler.codec.http.HttpHeaderNames, .HttpHeaderValues, .HttpMethod, org.reactivestreams.Publisher, reactor.netty5.BufferFlux, reactor.netty5.http.websocket.WebsocketInbound, .WebsocketOutbound, reactor.util.annotation.Nullable

Server routes are unique and only the first matching in order of declaration will be invoked.
Author
Stephane Maldini

Field Summary

Modifier and TypeField and Description
public static final Predicate<HttpServerRequest>

Method Summary

Modifier and TypeMethod and Description
public HttpServerRoutes

Returns:

this HttpServerRoutes
comparator
(Comparator<HttpRouteHandlerMetadata>
a HttpRouteHandlerMetadata comparator.
comparator
)

Use the provided java.util.Comparator to sort routes, rather than using configured order.Routes that were already configured are also impacted by this change and will be sorted according to the comparator.You can revert to using the declaration order by calling the noComparator() method (which is the default).

public default HttpServerRoutes

Returns:

this HttpServerRoutes
delete
(String
The DELETE path used by clients.
path
,
BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>
an I/O handler to invoke for the given condition
handler
)

Listens for HTTP DELETE on the passed path to be used as a routing condition.

public default HttpServerRoutes

Returns:

this HttpServerRoutes
directory
(String
The GET path used by clients
uri
,
Path
the root prefix to serve from the file system, e.g. "/Users/me/resources"
directory
)

Listens for HTTP GET on the passed path to be used as a routing condition.

public HttpServerRoutes

Returns:

this HttpServerRoutes
directory
(String
The GET path used by clients
uri
,
Path
the root prefix to serve from the file system, e.g. "/Users/me/resources"
directory
,
Function<HttpServerResponse, HttpServerResponse>
a pre response processor
interceptor
)

Listens for HTTP GET on the passed path to be used as a routing condition.The content of the provided directory will be served.

public default HttpServerRoutes

Returns:

this HttpServerRoutes
file
(String
The GET path used by clients
uri
,
Path
the resource Path to serve
path
)

Listens for HTTP GET on the passed path to be used as a routing condition.

public default HttpServerRoutes

Returns:

this HttpServerRoutes
file
(String
The GET path used by clients
uri
,
String
the resource path to serve
path
)

Listens for HTTP GET on the passed path to be used as a routing condition.

public default HttpServerRoutes

Returns:

this HttpServerRoutes
file
(Predicate<HttpServerRequest>
The HttpPredicate to use to trigger the route, pattern matching and capture are supported
uri
,
Path
the Path to the file to serve
path
,
Function<HttpServerResponse, HttpServerResponse>
a channel pre-intercepting handler e.g. for content type header
interceptor
)

Listens for HTTP GET on the passed path to be used as a routing condition.

public default HttpServerRoutes

Returns:

this HttpServerRoutes
get
(String
The GET path used by clients
path
,
BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>
an I/O handler to invoke for the given condition
handler
)

Listens for HTTP GET on the passed path to be used as a routing condition.

public default HttpServerRoutes

Returns:

this HttpServerRoutes
head
(String
The HEAD path used by clients
path
,
BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>
an I/O handler to invoke for the given condition
handler
)

Listens for HTTP HEAD on the passed path to be used as a routing condition.

public default HttpServerRoutes

Returns:

this HttpServerRoutes
index
(final BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>
an I/O handler to invoke on index/root request
handler
)

This route will be invoked when GET "/path" or "/path/" like uri are requested.

public static HttpServerRoutes

Returns:

a new default routing registry HttpServerRoutes
newRoutes
()

Returns a new default routing registry HttpServerRoutes

public HttpServerRoutes

Returns:

this HttpServerRoutes
noComparator
()

Removes any previously applied java.util.Comparator customization using HttpServerRoutes#comparator(Comparator), and use the order in which the routes were configured.

public default HttpServerRoutes

Returns:

this HttpServerRoutes
options
(String
The OPTIONS path used by clients
path
,
BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>
an I/O handler to invoke for the given condition
handler
)

Listens for HTTP OPTIONS on the passed path to be used as a routing condition.

public default HttpServerRoutes

Returns:

this HttpServerRoutes
post
(String
The POST path used by clients
path
,
BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>
an I/O handler to invoke for the given condition
handler
)

Listens for HTTP POST on the passed path to be used as a routing condition.

public default HttpServerRoutes

Returns:

this HttpServerRoutes
put
(String
The PUT path used by clients
path
,
BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>
an I/O handler to invoke for the given condition
handler
)

Listens for HTTP PUT on the passed path to be used as a routing condition.

public HttpServerRoutes

Returns:

this HttpServerRoutes
removeIf
(Predicate<? super HttpRouteHandlerMetadata>
a predicate given each http route handler HttpRouteHandlerMetadata
condition
)

A generic route predicate that if matched already register I/O handler use HttpServerRoutes#route(Predicate, BiFunction) will be removed.

public HttpServerRoutes

Returns:

this HttpServerRoutes
route
(Predicate<? super HttpServerRequest>
a predicate given each inbound request
condition
,
BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>
the I/O handler to invoke on match
handler
)

A generic route predicate that if matched invoke the passed I/O handler.

public default HttpServerRoutes

Returns:

this HttpServerRoutes
ws
(String
The websocket path used by clients
path
,
BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>>
an I/O handler to invoke for the given condition
handler
)

Listens for websocket on the passed path to be used as a routing condition.

public default HttpServerRoutes

Returns:

this HttpServerRoutes
ws
(String
The websocket path used by clients
path
,
BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>>
an I/O handler to invoke for the given condition
handler
,
WebsocketServerSpec
WebsocketServerSpec for websocket configuration
configurer
)

Listens for websocket on the passed path to be used as a routing condition.

public default HttpServerRoutes

Returns:

this HttpServerRoutes
ws
(Predicate<? super HttpServerRequest>
a predicate given each inbound request
condition
,
BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>>
an I/O handler to invoke for the given condition
handler
,
WebsocketServerSpec
WebsocketServerSpec for websocket configuration
websocketServerSpec
)

Listens for websocket with the given route predicate to invoke the matching handler.

Inherited from java.util.function.BiFunction:
andThenapply

Field Detail

INDEX_PREDICATEback to summary
public static final Predicate<HttpServerRequest> INDEX_PREDICATE

Method Detail

comparatorback to summary
public HttpServerRoutes comparator(Comparator<HttpRouteHandlerMetadata> comparator)

Use the provided java.util.Comparator to sort routes, rather than using configured order.Routes that were already configured are also impacted by this change and will be sorted according to the comparator.You can revert to using the declaration order by calling the noComparator() method (which is the default).

Parameters
comparator:Comparator<HttpRouteHandlerMetadata>

a HttpRouteHandlerMetadata comparator.

Returns:HttpServerRoutes

this HttpServerRoutes

Since
1.0.7
deleteback to summary
public default HttpServerRoutes delete(String path, BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> handler)

Listens for HTTP DELETE on the passed path to be used as a routing condition. Incoming connections will query the internal registry to invoke the matching handler.

Additional regex matching is available, e.g. "/test/{param}". Params are resolved using HttpServerRequest#param(CharSequence)

Parameters
path:String

The DELETE path used by clients.

handler:BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>

an I/O handler to invoke for the given condition

Returns:HttpServerRoutes

this HttpServerRoutes

directoryback to summary
public default HttpServerRoutes directory(String uri, Path directory)

Listens for HTTP GET on the passed path to be used as a routing condition. The content of the provided directory will be served.

Additional regex matching is available, e.g. "/test/{param}". Params are resolved using HttpServerRequest#param(CharSequence)

Parameters
uri:String

The GET path used by clients

directory:Path

the root prefix to serve from the file system, e.g. "/Users/me/resources"

Returns:HttpServerRoutes

this HttpServerRoutes

directoryback to summary
public HttpServerRoutes directory(String uri, Path directory, Function<HttpServerResponse, HttpServerResponse> interceptor)

Listens for HTTP GET on the passed path to be used as a routing condition.The content of the provided directory will be served.

Additional regex matching is available, e.g. "/test/{param}". Params are resolved using HttpServerRequest#param(CharSequence)

Parameters
uri:String

The GET path used by clients

directory:Path

the root prefix to serve from the file system, e.g. "/Users/me/resources"

interceptor:Function<HttpServerResponse, HttpServerResponse>

a pre response processor

Returns:HttpServerRoutes

this HttpServerRoutes

fileback to summary
public default HttpServerRoutes file(String uri, Path path)

Listens for HTTP GET on the passed path to be used as a routing condition. The provided java.io.File will be served.

Additional regex matching is available, e.g. "/test/{param}". Params are resolved using HttpServerRequest#param(CharSequence)

Parameters
uri:String

The GET path used by clients

path:Path

the resource Path to serve

Returns:HttpServerRoutes

this HttpServerRoutes

fileback to summary
public default HttpServerRoutes file(String uri, String path)

Listens for HTTP GET on the passed path to be used as a routing condition. The file at provided path will be served.

Additional regex matching is available, e.g. "/test/{param}". Params are resolved using HttpServerRequest#param(CharSequence)

Parameters
uri:String

The GET path used by clients

path:String

the resource path to serve

Returns:HttpServerRoutes

this HttpServerRoutes

fileback to summary
public default HttpServerRoutes file(Predicate<HttpServerRequest> uri, Path path, Function<HttpServerResponse, HttpServerResponse> interceptor)

Listens for HTTP GET on the passed path to be used as a routing condition. The file on the provided Path is served.

Additional regex matching is available e.g. "/test/{param}". Params are resolved using HttpServerRequest#param(CharSequence)

Parameters
uri:Predicate<HttpServerRequest>

The HttpPredicate to use to trigger the route, pattern matching and capture are supported

path:Path

the Path to the file to serve

interceptor:Function<HttpServerResponse, HttpServerResponse>

a channel pre-intercepting handler e.g. for content type header

Returns:HttpServerRoutes

this HttpServerRoutes

getback to summary
public default HttpServerRoutes get(String path, BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> handler)

Listens for HTTP GET on the passed path to be used as a routing condition. Incoming connections will query the internal registry to invoke the matching handler.

Additional regex matching is available e.g. "/test/{param}". Params are resolved using HttpServerRequest#param(CharSequence)

Parameters
path:String

The GET path used by clients

handler:BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>

an I/O handler to invoke for the given condition

Returns:HttpServerRoutes

this HttpServerRoutes

headback to summary
public default HttpServerRoutes head(String path, BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> handler)

Listens for HTTP HEAD on the passed path to be used as a routing condition. Incoming connections will query the internal registry to invoke the matching handler.

Additional regex matching is available e.g. "/test/{param}". Params are resolved using HttpServerRequest#param(CharSequence)

Parameters
path:String

The HEAD path used by clients

handler:BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>

an I/O handler to invoke for the given condition

Returns:HttpServerRoutes

this HttpServerRoutes

indexback to summary
public default HttpServerRoutes index(final BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> handler)

This route will be invoked when GET "/path" or "/path/" like uri are requested.

Parameters
handler:BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>

an I/O handler to invoke on index/root request

Returns:HttpServerRoutes

this HttpServerRoutes

newRoutesback to summary
public static HttpServerRoutes newRoutes()

Returns a new default routing registry HttpServerRoutes

Returns:HttpServerRoutes

a new default routing registry HttpServerRoutes

noComparatorback to summary
public HttpServerRoutes noComparator()

Removes any previously applied java.util.Comparator customization using HttpServerRoutes#comparator(Comparator), and use the order in which the routes were configured.

Returns:HttpServerRoutes

this HttpServerRoutes

Since
1.0.7
optionsback to summary
public default HttpServerRoutes options(String path, BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> handler)

Listens for HTTP OPTIONS on the passed path to be used as a routing condition. Incoming connections will query the internal registry to invoke the matching handler.

Additional regex matching is available e.g. "/test/{param}". Params are resolved using HttpServerRequest#param(CharSequence)

Parameters
path:String

The OPTIONS path used by clients

handler:BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>

an I/O handler to invoke for the given condition

Returns:HttpServerRoutes

this HttpServerRoutes

postback to summary
public default HttpServerRoutes post(String path, BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> handler)

Listens for HTTP POST on the passed path to be used as a routing condition. Incoming connections will query the internal registry to invoke the matching handler.

Additional regex matching is available e.g. "/test/{param}". Params are resolved using HttpServerRequest#param(CharSequence)

Parameters
path:String

The POST path used by clients

handler:BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>

an I/O handler to invoke for the given condition

Returns:HttpServerRoutes

this HttpServerRoutes

putback to summary
public default HttpServerRoutes put(String path, BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> handler)

Listens for HTTP PUT on the passed path to be used as a routing condition. Incoming connections will query the internal registry to invoke the matching handler.

Additional regex matching is available e.g. "/test/{param}". Params are resolved using HttpServerRequest#param(CharSequence)

Parameters
path:String

The PUT path used by clients

handler:BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>

an I/O handler to invoke for the given condition

Returns:HttpServerRoutes

this HttpServerRoutes

removeIfback to summary
public HttpServerRoutes removeIf(Predicate<? super HttpRouteHandlerMetadata> condition)

A generic route predicate that if matched already register I/O handler use HttpServerRoutes#route(Predicate, BiFunction) will be removed.

Parameters
condition:Predicate<? super HttpRouteHandlerMetadata>

a predicate given each http route handler HttpRouteHandlerMetadata

Returns:HttpServerRoutes

this HttpServerRoutes

Since
1.0.11
routeback to summary
public HttpServerRoutes route(Predicate<? super HttpServerRequest> condition, BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> handler)

A generic route predicate that if matched invoke the passed I/O handler.

Parameters
condition:Predicate<? super HttpServerRequest>

a predicate given each inbound request

handler:BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>

the I/O handler to invoke on match

Returns:HttpServerRoutes

this HttpServerRoutes

wsback to summary
public default HttpServerRoutes ws(String path, BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>> handler)

Listens for websocket on the passed path to be used as a routing condition. Incoming connections will query the internal registry to invoke the matching handler.

Additional regex matching is available e.g. "/test/{param}". Params are resolved using HttpServerRequest#param(CharSequence) They are NOT accessible in the I/O handler provided as parameter.

Parameters
path:String

The websocket path used by clients

handler:BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>>

an I/O handler to invoke for the given condition

Returns:HttpServerRoutes

this HttpServerRoutes

wsback to summary
public default HttpServerRoutes ws(String path, BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>> handler, WebsocketServerSpec configurer)

Listens for websocket on the passed path to be used as a routing condition. Incoming connections will query the internal registry to invoke the matching handler.

Additional regex matching is available e.g. "/test/{param}". Params are resolved using HttpServerRequest#param(CharSequence) They are NOT accessible in the handler provided as parameter.

Parameters
path:String

The websocket path used by clients

handler:BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>>

an I/O handler to invoke for the given condition

configurer:WebsocketServerSpec

WebsocketServerSpec for websocket configuration

Returns:HttpServerRoutes

this HttpServerRoutes

Since
0.9.5
wsback to summary
public default HttpServerRoutes ws(Predicate<? super HttpServerRequest> condition, BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>> handler, WebsocketServerSpec websocketServerSpec)

Listens for websocket with the given route predicate to invoke the matching handler.

Parameters
condition:Predicate<? super HttpServerRequest>

a predicate given each inbound request

handler:BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>>

an I/O handler to invoke for the given condition

websocketServerSpec:WebsocketServerSpec

WebsocketServerSpec for websocket configuration

Returns:HttpServerRoutes

this HttpServerRoutes

Since
0.9.5