A router receives request from an 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.
Constructor and description |
---|
Router
(java.lang.Object delegate) |
Type | Name and description |
---|---|
void |
accept(HttpServerRequest request) This method is used to provide a request to the router. |
Router |
clear() Remove all the routes from this router |
Route |
connect() Add a route that matches any HTTP CONNECT request |
Route |
connect(java.lang.String path) Add a route that matches a HTTP CONNECT request and the specified path |
Route |
connectWithRegex(java.lang.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(java.lang.String path) Add a route that matches a HTTP DELETE request and the specified path |
Route |
deleteWithRegex(java.lang.String regex) Add a route that matches a HTTP DELETE request and the specified path regex |
Router |
exceptionHandler(io.vertx.core.Handler<java.lang.Throwable> exceptionHandler) Specify a handler for any unhandled exceptions on this router. |
Route |
get() Add a route that matches any HTTP GET request |
Route |
get(java.lang.String path) Add a route that matches a HTTP GET request and the specified path |
java.lang.Object |
getDelegate() |
java.util.List<Route> |
getRoutes() @return
|
Route |
getWithRegex(java.lang.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(java.lang.String path) Add a route that matches a HTTP HEAD request and the specified path |
Route |
headWithRegex(java.lang.String regex) Add a route that matches a HTTP HEAD request and the specified path regex |
Router |
mountSubRouter(java.lang.String mountPoint, Router subRouter) Mount a sub router on this router |
Route |
options() Add a route that matches any HTTP OPTIONS request |
Route |
options(java.lang.String path) Add a route that matches a HTTP OPTIONS request and the specified path |
Route |
optionsWithRegex(java.lang.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(java.lang.String path) Add a route that matches a HTTP PATCH request and the specified path |
Route |
patchWithRegex(java.lang.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(java.lang.String path) Add a route that matches a HTTP POST request and the specified path |
Route |
postWithRegex(java.lang.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(java.lang.String path) Add a route that matches a HTTP PUT request and the specified path |
Route |
putWithRegex(java.lang.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. it matches all requests or failures. |
Route |
route(io.vertx.core.http.HttpMethod method, java.lang.String path) Add a route that matches the specified HTTP method and path |
Route |
route(java.lang.String path) Add a route that matches the specified path |
Route |
routeWithRegex(io.vertx.core.http.HttpMethod method, java.lang.String regex) Add a route that matches the specified HTTP method and path regex |
Route |
routeWithRegex(java.lang.String regex) Add a route that matches the specified path regex |
static Router |
router(Vertx vertx) Create a router |
Route |
trace() Add a route that matches any HTTP TRACE request |
Route |
trace(java.lang.String path) Add a route that matches a HTTP TRACE request and the specified path |
Route |
traceWithRegex(java.lang.String regex) Add a route that matches a HTTP TRACE request and the specified path regex |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
This method is used to provide a request to the router. Usually you take request from the HttpServer.requestHandler and pass it to this method. The router then routes it to matching routes.
request
- the requestRemove all the routes from this router
Add a route that matches any HTTP CONNECT request
Add a route that matches a HTTP CONNECT request and the specified path
path
- URI paths that begin with this path will matchAdd a route that matches a HTTP CONNECT request and the specified path regex
regex
- URI paths that begin with a match for this regex will matchAdd a route that matches any HTTP DELETE request
Add a route that matches a HTTP DELETE request and the specified path
path
- URI paths that begin with this path will matchAdd a route that matches a HTTP DELETE request and the specified path regex
regex
- URI paths that begin with a match for this regex will matchSpecify a handler for any unhandled exceptions on this router. The handler will be called for exceptions thrown from handlers. This does not affect the normal failure routing logic.
exceptionHandler
- the exception handlerAdd a route that matches any HTTP GET request
Add a route that matches a HTTP GET request and the specified path
path
- URI paths that begin with this path will match
Add a route that matches a HTTP GET request and the specified path regex
regex
- URI paths that begin with a match for this regex will matchUsed to route a context to the router. Used for sub-routers. You wouldn't normally call this method directly.
context
- the routing contextUsed to route a failure to the router. Used for sub-routers. You wouldn't normally call this method directly.
context
- the routing contextAdd a route that matches any HTTP HEAD request
Add a route that matches a HTTP HEAD request and the specified path
path
- URI paths that begin with this path will matchAdd a route that matches a HTTP HEAD request and the specified path regex
regex
- URI paths that begin with a match for this regex will matchMount a sub router on this router
mountPoint
- the mount point (path prefix) to mount it onsubRouter
- the router to mount as a sub routerAdd a route that matches any HTTP OPTIONS request
Add a route that matches a HTTP OPTIONS request and the specified path
path
- URI paths that begin with this path will matchAdd a route that matches a HTTP OPTIONS request and the specified path regex
regex
- URI paths that begin with a match for this regex will matchAdd a route that matches any HTTP PATCH request
Add a route that matches a HTTP PATCH request and the specified path
path
- URI paths that begin with this path will matchAdd a route that matches a HTTP PATCH request and the specified path regex
regex
- URI paths that begin with a match for this regex will matchAdd a route that matches any HTTP POST request
Add a route that matches a HTTP POST request and the specified path
path
- URI paths that begin with this path will matchAdd a route that matches a HTTP POST request and the specified path regex
regex
- URI paths that begin with a match for this regex will matchAdd a route that matches any HTTP PUT request
Add a route that matches a HTTP PUT request and the specified path
path
- URI paths that begin with this path will matchAdd a route that matches a HTTP PUT request and the specified path regex
regex
- URI paths that begin with a match for this regex will matchAdd a route with no matching criteria, i.e. it matches all requests or failures.
Add a route that matches the specified HTTP method and path
method
- the HTTP method to matchpath
- URI paths that begin with this path will matchAdd a route that matches the specified path
path
- URI paths that begin with this path will matchAdd a route that matches the specified HTTP method and path regex
method
- the HTTP method to matchregex
- URI paths that begin with a match for this regex will matchAdd a route that matches the specified path regex
regex
- URI paths that begin with a match for this regex will matchCreate a router
vertx
- the Vert.x instanceAdd a route that matches any HTTP TRACE request
Add a route that matches a HTTP TRACE request and the specified path
path
- URI paths that begin with this path will matchAdd a route that matches a HTTP TRACE request and the specified path regex
regex
- URI paths that begin with a match for this regex will match