Interface HttpServerRoutes
- All Superinterfaces:
BiFunction<HttpServerRequest,
HttpServerResponse, Publisher<Void>>
- Author:
- Stephane Maldini
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptioncomparator
(Comparator<HttpRouteHandlerMetadata> comparator) Use the providedComparator
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 thenoComparator()
method (which is the default).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.default HttpServerRoutes
Listens for HTTP GET on the passed path to be used as a routing condition.directory
(String uri, Path directory, @Nullable Function<HttpServerResponse, HttpServerResponse> interceptor) Listens for HTTP GET on the passed path to be used as a routing condition.The content of the provideddirectory
will be served.default HttpServerRoutes
Listens for HTTP GET on the passed path to be used as a routing condition.default HttpServerRoutes
Listens for HTTP GET on the passed path to be used as a routing condition.default HttpServerRoutes
file
(Predicate<HttpServerRequest> uri, Path path, @Nullable Function<HttpServerResponse, HttpServerResponse> interceptor) Listens for HTTP GET on the passed path to be used as a routing condition.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.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.default HttpServerRoutes
index
(BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> handler) This route will be invoked when GET "/path" or "/path/" like uri are requested.static HttpServerRoutes
Returns a new default routing registryHttpServerRoutes
.Removes any previously appliedComparator
customization usingcomparator(Comparator)
, and use the order in which the routes were configured.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.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.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.removeIf
(Predicate<? super HttpRouteHandlerMetadata> condition) A generic route predicate that if matched already register I/O handler useroute(Predicate, BiFunction)
will be removed.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.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.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.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.Methods inherited from interface java.util.function.BiFunction
andThen, apply
-
Field Details
-
INDEX_PREDICATE
-
-
Method Details
-
newRoutes
Returns a new default routing registryHttpServerRoutes
.- Returns:
- a new default routing registry
HttpServerRoutes
-
delete
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
- The DELETE path used by clients.handler
- an I/O handler to invoke for the given condition- Returns:
- this
HttpServerRoutes
-
directory
Listens for HTTP GET on the passed path to be used as a routing condition. The content of the provideddirectory
will be served.Additional regex matching is available, e.g. "/test/{param}". Params are resolved using
HttpServerRequest.param(CharSequence)
- Parameters:
uri
- The GET path used by clientsdirectory
- the root prefix to serve from the file system, e.g. "/Users/me/resources"- Returns:
- this
HttpServerRoutes
-
directory
HttpServerRoutes directory(String uri, Path directory, @Nullable Function<HttpServerResponse, HttpServerResponse> interceptor) Listens for HTTP GET on the passed path to be used as a routing condition.The content of the provideddirectory
will be served.Additional regex matching is available, e.g. "/test/{param}". Params are resolved using
HttpServerRequest.param(CharSequence)
- Parameters:
uri
- The GET path used by clientsdirectory
- the root prefix to serve from the file system, e.g. "/Users/me/resources"interceptor
- a pre response processor- Returns:
- this
HttpServerRoutes
-
file
Listens for HTTP GET on the passed path to be used as a routing condition. The providedFile
will be served.Additional regex matching is available, e.g. "/test/{param}". Params are resolved using
HttpServerRequest.param(CharSequence)
- Parameters:
uri
- The GET path used by clientspath
- the resource Path to serve- Returns:
- this
HttpServerRoutes
-
file
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
- The GET path used by clientspath
- the resource path to serve- Returns:
- this
HttpServerRoutes
-
file
default HttpServerRoutes file(Predicate<HttpServerRequest> uri, Path path, @Nullable Function<HttpServerResponse, HttpServerResponse> interceptor) Listens for HTTP GET on the passed path to be used as a routing condition. The file on the providedPath
is served.Additional regex matching is available e.g. "/test/{param}". Params are resolved using
HttpServerRequest.param(CharSequence)
- Parameters:
uri
- TheHttpPredicate
to use to trigger the route, pattern matching and capture are supportedpath
- the Path to the file to serveinterceptor
- a channel pre-intercepting handler e.g. for content type header- Returns:
- this
HttpServerRoutes
-
get
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
- The GET path used by clientshandler
- an I/O handler to invoke for the given condition- Returns:
- this
HttpServerRoutes
-
head
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
- The HEAD path used by clientshandler
- an I/O handler to invoke for the given condition- Returns:
- this
HttpServerRoutes
-
index
default HttpServerRoutes index(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
- an I/O handler to invoke on index/root request- Returns:
- this
HttpServerRoutes
-
options
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
- The OPTIONS path used by clientshandler
- an I/O handler to invoke for the given condition- Returns:
- this
HttpServerRoutes
-
post
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
- The POST path used by clientshandler
- an I/O handler to invoke for the given condition- Returns:
- this
HttpServerRoutes
-
put
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
- The PUT path used by clientshandler
- an I/O handler to invoke for the given condition- Returns:
- this
HttpServerRoutes
-
removeIf
A generic route predicate that if matched already register I/O handler useroute(Predicate, BiFunction)
will be removed.- Parameters:
condition
- a predicate given each http route handlerHttpRouteHandlerMetadata
- Returns:
- this
HttpServerRoutes
- Since:
- 1.0.11
-
route
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
- a predicate given each inbound requesthandler
- the I/O handler to invoke on match- Returns:
- this
HttpServerRoutes
-
comparator
Use the providedComparator
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 thenoComparator()
method (which is the default).- Parameters:
comparator
- a HttpRouteHandlerMetadata comparator.- Returns:
- this
HttpServerRoutes
- Since:
- 1.0.7
-
noComparator
HttpServerRoutes noComparator()Removes any previously appliedComparator
customization usingcomparator(Comparator)
, and use the order in which the routes were configured.- Returns:
- this
HttpServerRoutes
- Since:
- 1.0.7
-
ws
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
- The websocket path used by clientshandler
- an I/O handler to invoke for the given condition- Returns:
- this
HttpServerRoutes
-
ws
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
- The websocket path used by clientshandler
- an I/O handler to invoke for the given conditionconfigurer
-WebsocketServerSpec
for websocket configuration- Returns:
- this
HttpServerRoutes
- Since:
- 0.9.5
-
ws
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
- a predicate given each inbound requesthandler
- an I/O handler to invoke for the given conditionwebsocketServerSpec
-WebsocketServerSpec
for websocket configuration- Returns:
- this
HttpServerRoutes
- Since:
- 0.9.5
-