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 |
---|---|
default void |
accept(HttpServerRequest request)
Deprecated.
|
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.
|
Router |
exceptionHandler(Handler<Throwable> exceptionHandler)
Deprecated.
you should use
errorHandler(int, Handler) with 500 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
|
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
|
Router |
modifiedHandler(Handler<Router> handler)
When a Router routes are changed this handler is notified.
|
Router |
mountSubRouter(String mountPoint,
Router subRouter)
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
|
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
|
static Router router(Vertx vertx)
vertx
- the Vert.x instance@Deprecated default void accept(HttpServerRequest request)
HttpServer.requestHandler(Handler)
and pass it to this method. The
router then routes it to matching routes.
This method is now deprecated you can use this object directly as a request handler, which
means there is no need for a method reference anymore.request
- the requestRoute 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()
Router mountSubRouter(String mountPoint, Router subRouter)
mountPoint
- the mount point (path prefix) to mount it onsubRouter
- the router to mount as a sub router@Deprecated Router exceptionHandler(Handler<Throwable> exceptionHandler)
errorHandler(int, Handler)
with 500 status codeexceptionHandler
- the exception handlerRouter 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 argumentCopyright © 2023 Eclipse. All rights reserved.