public interface Route
Modifier and Type | Method and Description |
---|---|
Route |
blockingHandler(Handler<RoutingContext> requestHandler)
Like
blockingHandler(Handler, boolean) called with ordered = true |
Route |
blockingHandler(Handler<RoutingContext> requestHandler,
boolean ordered)
Specify a blocking request handler for the route.
|
Route |
consumes(String contentType)
Add a content type consumed by this route.
|
Route |
disable()
Disable this route.
|
Route |
enable()
Enable this route.
|
Route |
failureHandler(Handler<RoutingContext> failureHandler)
Append a failure handler to the route failure handlers list.
|
default <T> T |
getMetadata(String key)
Get some data from metadata.
|
String |
getName() |
String |
getPath() |
Route |
handler(Handler<RoutingContext> requestHandler)
Append a request handler to the route handlers list.
|
boolean |
isExactPath()
Returns true of the path doesn't end with a wildcard
* or is null . |
boolean |
isRegexPath()
Returns true of the path is a regular expression, this includes expression paths.
|
Route |
last()
Specify this is the last route for the router.
|
Map<String,Object> |
metadata() |
Route |
method(HttpMethod method)
Add an HTTP method for this route.
|
Set<HttpMethod> |
methods() |
Route |
order(int order)
Specify the order for this route.
|
Route |
path(String path)
Set the path prefix for this route.
|
Route |
pathRegex(String path)
Set the path prefix as a regular expression.
|
Route |
produces(String contentType)
Add a content type produced by this route.
|
Route |
putMetadata(String key,
Object value)
Put metadata to this route.
|
Route |
remove()
Remove this route from the router
|
default <T> Route |
respond(java.util.function.Function<RoutingContext,Future<T>> function)
Append a function request handler to the route handlers list.
|
Route |
setName(String name)
Giving a name to a route will provide this name as metadata to requests matching this route.
|
Route |
setRegexGroupsNames(List<String> groups)
When you add a new route with a regular expression, you can add named capture groups for parameters.
|
Route |
subRouter(Router subRouter)
Use a (sub)
Router as a handler. |
default Route |
useNormalisedPath(boolean useNormalizedPath)
Deprecated.
|
Route |
useNormalizedPath(boolean useNormalizedPath)
If true then the normalized request path will be used when routing (e.g.
|
Route |
virtualHost(String hostnamePattern)
Add a virtual host filter for this route.
|
Route putMetadata(String key, Object value)
key
- the metadata of keyvalue
- the metadata of valueRoute method(HttpMethod method)
method
- the HTTP method to addRoute path(String path)
path
- the path prefixRoute pathRegex(String path)
path
- the path regexRoute produces(String contentType)
contentType
- the content typeRoute consumes(String contentType)
contentType
- the content typeRoute virtualHost(String hostnamePattern)
hostnamePattern
- the hostname pattern that should match Host
header of the requestsRoute order(int order)
order
- the orderRoute last()
Route handler(Handler<RoutingContext> requestHandler)
requestHandler
- the request handlerRoute blockingHandler(Handler<RoutingContext> requestHandler)
blockingHandler(Handler, boolean)
called with ordered = trueRoute subRouter(Router subRouter)
Router
as a handler. There are several requirements to be fulfilled for this
to be accepted.
subRouter
- the router to addRoute blockingHandler(Handler<RoutingContext> requestHandler, boolean ordered)
handler(Handler)
excepted that it will run the blocking handler on a worker thread
so that it won't block the event loop. Note that it's safe to call context.next() from the
blocking handler as it will be executed on the event loop context (and not on the worker thread.
If the blocking handler is ordered it means that any blocking handlers for the same context are never executed concurrently but always in the order they were called. The default value of ordered is true. If you do not want this behaviour and don't mind if your blocking handlers are executed in parallel you can set ordered to false.
requestHandler
- the blocking request handlerordered
- if true handlers are executed in sequence, otherwise are run in parallelRoute failureHandler(Handler<RoutingContext> failureHandler)
failureHandler
- the request handlerRoute remove()
Route disable()
Route enable()
@Deprecated default Route useNormalisedPath(boolean useNormalizedPath)
useNormalizedPath(boolean)
insteadRoute useNormalizedPath(boolean useNormalizedPath)
useNormalizedPath
- use normalized path for routing?default <T> T getMetadata(String key)
T
- the type of the datakey
- the key for the metadataString getPath()
boolean isRegexPath()
boolean isExactPath()
*
or is null
.
Regular expression paths are always assumed to be exact.Set<HttpMethod> methods()
Route setRegexGroupsNames(List<String> groups)
groups
- group namesRoute setName(String name)
name
- The name of the route.String getName()
default <T> Route respond(java.util.function.Function<RoutingContext,Future<T>> function)
Future
. The use of this functional interface allows users to quickly
link the responses from other vert.x APIs or clients directly to a handler. If the context response has been ended,
for example, RoutingContext.end()
has been called, then nothing shall happen. For the remaining cases, the
following rules apply:
body
is null
then the status code of the response shall be 204 (NO CONTENT)body
is of type Buffer
and the Content-Type
isn't set then the Content-Type
shall be application/octet-stream
body
is of type String
and the Content-Type
isn't set then the Content-Type
shall be text/html
RoutingContext.json(Object)
to perform a JSON serialization of the resultT
- a generic type to allow type safe APIfunction
- the request handler functionCopyright © 2023 Eclipse. All rights reserved.