public interface Router extends Handler<HttpServerRequest>
HttpServer
and routes it to the first matching
Route
that it contains. A router can contain many routes.
Routers are also used for routing failures.
Modifier and Type | Method and Description |
---|---|
Router |
allowForward(AllowForwardHeaders allowForwardHeaders)
Set whether the router should parse "forwarded"-type headers
|
Router |
clear()
Remove all the routes from this router
|
Route |
connect()
Add a route that matches any HTTP CONNECT request
|
Route |
connect(String path)
Add a route that matches a HTTP CONNECT request and the specified path
|
Route |
connectWithRegex(String regex)
Add a route that matches a HTTP CONNECT request and the specified path regex
|
Route |
delete()
Add a route that matches any HTTP DELETE request
|
Route |
delete(String path)
Add a route that matches a HTTP DELETE request and the specified path
|
Route |
deleteWithRegex(String regex)
Add a route that matches a HTTP DELETE request and the specified path regex
|
Router |
errorHandler(int statusCode,
Handler<RoutingContext> errorHandler)
Specify an handler to handle an error for a particular status code.
|
Route |
get()
Add a route that matches any HTTP GET request
|
Route |
get(String path)
Add a route that matches a HTTP GET request and the specified path
|
default <T> T |
getMetadata(String key)
Get some data from metadata.
|
List<Route> |
getRoutes() |
Route |
getWithRegex(String regex)
Add a route that matches a HTTP GET request and the specified path regex
|
void |
handleContext(RoutingContext context)
Used to route a context to the router.
|
void |
handleFailure(RoutingContext context)
Used to route a failure to the router.
|
Route |
head()
Add a route that matches any HTTP HEAD request
|
Route |
head(String path)
Add a route that matches a HTTP HEAD request and the specified path
|
Route |
headWithRegex(String regex)
Add a route that matches a HTTP HEAD request and the specified path regex
|
Map<String,Object> |
metadata() |
Router |
modifiedHandler(Handler<Router> handler)
When a Router routes are changed this handler is notified.
|
Route |
mountSubRouter(String mountPoint,
Router subRouter)
Deprecated.
This method duplicates the sub router functionality from
Route.subRouter(Router) .
Mount a sub router on this router |
Route |
options()
Add a route that matches any HTTP OPTIONS request
|
Route |
options(String path)
Add a route that matches a HTTP OPTIONS request and the specified path
|
Route |
optionsWithRegex(String regex)
Add a route that matches a HTTP OPTIONS request and the specified path regex
|
Route |
patch()
Add a route that matches any HTTP PATCH request
|
Route |
patch(String path)
Add a route that matches a HTTP PATCH request and the specified path
|
Route |
patchWithRegex(String regex)
Add a route that matches a HTTP PATCH request and the specified path regex
|
Route |
post()
Add a route that matches any HTTP POST request
|
Route |
post(String path)
Add a route that matches a HTTP POST request and the specified path
|
Route |
postWithRegex(String regex)
Add a route that matches a HTTP POST request and the specified path regex
|
Route |
put()
Add a route that matches any HTTP PUT request
|
Route |
put(String path)
Add a route that matches a HTTP PUT request and the specified path
|
Router |
putMetadata(String key,
Object value)
Put metadata to this router.
|
Route |
putWithRegex(String regex)
Add a route that matches a HTTP PUT request and the specified path regex
|
Route |
route()
Add a route with no matching criteria, i.e.
|
Route |
route(HttpMethod method,
String path)
Add a route that matches the specified HTTP method and path
|
Route |
route(String path)
Add a route that matches the specified path
|
static Router |
router(Vertx vertx)
Create a router
|
Route |
routeWithRegex(HttpMethod method,
String regex)
Add a route that matches the specified HTTP method and path regex
|
Route |
routeWithRegex(String regex)
Add a route that matches the specified path regex
|
Route |
trace()
Add a route that matches any HTTP TRACE request
|
Route |
trace(String path)
Add a route that matches a HTTP TRACE request and the specified path
|
Route |
traceWithRegex(String regex)
Add a route that matches a HTTP TRACE request and the specified path regex
|
Router putMetadata(String key, Object value)
key
- the metadata of keyvalue
- the metadata of valuedefault <T> T getMetadata(String key)
T
- the type of the datakey
- the key for the metadatastatic Router router(Vertx vertx)
vertx
- the Vert.x instanceRoute route()
Route route(HttpMethod method, String path)
method
- the HTTP method to matchpath
- URI paths that begin with this path will matchRoute route(String path)
path
- URI paths that begin with this path will matchRoute routeWithRegex(HttpMethod method, String regex)
method
- the HTTP method to matchregex
- URI paths that begin with a match for this regex will matchRoute routeWithRegex(String regex)
regex
- URI paths that begin with a match for this regex will matchRoute get()
Route get(String path)
path
- URI paths that begin with this path will matchRoute getWithRegex(String regex)
regex
- URI paths that begin with a match for this regex will matchRoute head()
Route head(String path)
path
- URI paths that begin with this path will matchRoute headWithRegex(String regex)
regex
- URI paths that begin with a match for this regex will matchRoute options()
Route options(String path)
path
- URI paths that begin with this path will matchRoute optionsWithRegex(String regex)
regex
- URI paths that begin with a match for this regex will matchRoute put()
Route put(String path)
path
- URI paths that begin with this path will matchRoute putWithRegex(String regex)
regex
- URI paths that begin with a match for this regex will matchRoute post()
Route post(String path)
path
- URI paths that begin with this path will matchRoute postWithRegex(String regex)
regex
- URI paths that begin with a match for this regex will matchRoute delete()
Route delete(String path)
path
- URI paths that begin with this path will matchRoute deleteWithRegex(String regex)
regex
- URI paths that begin with a match for this regex will matchRoute trace()
Route trace(String path)
path
- URI paths that begin with this path will matchRoute traceWithRegex(String regex)
regex
- URI paths that begin with a match for this regex will matchRoute connect()
Route connect(String path)
path
- URI paths that begin with this path will matchRoute connectWithRegex(String regex)
regex
- URI paths that begin with a match for this regex will matchRoute patch()
Route patch(String path)
path
- URI paths that begin with this path will matchRoute patchWithRegex(String regex)
regex
- URI paths that begin with a match for this regex will matchRouter clear()
@Deprecated Route mountSubRouter(String mountPoint, Router subRouter)
Route.subRouter(Router)
.
Mount a sub router on this routermountPoint
- the mount point (path prefix) to mount it onsubRouter
- the router to mount as a sub routerRouter errorHandler(int statusCode, Handler<RoutingContext> errorHandler)
RoutingContext.next()
inside the error handler
This does not affect the normal failure routing logic.statusCode
- status code the errorHandler is capable of handleerrorHandler
- error handler. Note: You must not use RoutingContext.next()
inside the provided handlervoid handleContext(RoutingContext context)
context
- the routing contextvoid handleFailure(RoutingContext context)
context
- the routing contextRouter modifiedHandler(Handler<Router> handler)
handler
- a notification handler that will receive this router as argumentRouter allowForward(AllowForwardHeaders allowForwardHeaders)
allowForwardHeaders
- to enable parsing of "forwarded"-type headersCopyright © 2024 Eclipse. All rights reserved.