Interface Router
- All Superinterfaces:
Handler<HttpServerRequest>
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.
- Author:
- Tim Fox
-
Method Summary
Modifier and TypeMethodDescriptionallowForward(AllowForwardHeaders allowForwardHeaders) Set whether the router should parse "forwarded"-type headersclear()Remove all the routes from this routerconnect()Add a route that matches any HTTP CONNECT requestAdd a route that matches a HTTP CONNECT request and the specified pathconnectWithRegex(String regex) Add a route that matches a HTTP CONNECT request and the specified path regexdelete()Add a route that matches any HTTP DELETE requestAdd a route that matches a HTTP DELETE request and the specified pathdeleteWithRegex(String regex) Add a route that matches a HTTP DELETE request and the specified path regexerrorHandler(int statusCode, Handler<RoutingContext> errorHandler) Specify an handler to handle an error for a particular status code.get()Add a route that matches any HTTP GET requestAdd a route that matches a HTTP GET request and the specified pathdefault <T> TgetMetadata(String key) Get some data from metadata.getWithRegex(String regex) Add a route that matches a HTTP GET request and the specified path regexvoidhandleContext(RoutingContext context) Used to route a context to the router.voidhandleFailure(RoutingContext context) Used to route a failure to the router.head()Add a route that matches any HTTP HEAD requestAdd a route that matches a HTTP HEAD request and the specified pathheadWithRegex(String regex) Add a route that matches a HTTP HEAD request and the specified path regexmetadata()modifiedHandler(Handler<Router> handler) When a Router routes are changed this handler is notified.options()Add a route that matches any HTTP OPTIONS requestAdd a route that matches a HTTP OPTIONS request and the specified pathoptionsWithRegex(String regex) Add a route that matches a HTTP OPTIONS request and the specified path regexpatch()Add a route that matches any HTTP PATCH requestAdd a route that matches a HTTP PATCH request and the specified pathpatchWithRegex(String regex) Add a route that matches a HTTP PATCH request and the specified path regexpost()Add a route that matches any HTTP POST requestAdd a route that matches a HTTP POST request and the specified pathpostWithRegex(String regex) Add a route that matches a HTTP POST request and the specified path regexput()Add a route that matches any HTTP PUT requestAdd a route that matches a HTTP PUT request and the specified pathputMetadata(String key, Object value) Put metadata to this router.putWithRegex(String regex) Add a route that matches a HTTP PUT request and the specified path regexroute()Add a route with no matching criteria, i.e. it matches all requests or failures.route(HttpMethod method, String path) Add a route that matches the specified HTTP method and pathAdd a route that matches the specified pathstatic RouterCreate a routerrouteWithRegex(HttpMethod method, String regex) Add a route that matches the specified HTTP method and path regexrouteWithRegex(String regex) Add a route that matches the specified path regextrace()Add a route that matches any HTTP TRACE requestAdd a route that matches a HTTP TRACE request and the specified pathtraceWithRegex(String regex) Add a route that matches a HTTP TRACE request and the specified path regexuncaughtErrorHandler(Handler<RoutingContext> errorHandler) Specify an handler to handle an error for any status code that doesn't have a specific handler assigned.
-
Method Details
-
putMetadata
-
metadata
-
getMetadata
Get some data from metadata.- Type Parameters:
T- the type of the data- Parameters:
key- the key for the metadata- Returns:
- the data
-
router
-
route
Route route()Add a route with no matching criteria, i.e. it matches all requests or failures.- Returns:
- the route
-
route
Add a route that matches the specified HTTP method and path- Parameters:
method- the HTTP method to matchpath- URI paths that begin with this path will match- Returns:
- the route
-
route
-
routeWithRegex
Add a route that matches the specified HTTP method and path regex- Parameters:
method- the HTTP method to matchregex- URI paths that begin with a match for this regex will match- Returns:
- the route
-
routeWithRegex
-
get
-
get
-
getWithRegex
-
head
-
head
-
headWithRegex
-
options
-
options
-
optionsWithRegex
-
put
-
put
-
putWithRegex
-
post
-
post
-
postWithRegex
-
delete
-
delete
-
deleteWithRegex
-
trace
-
trace
-
traceWithRegex
-
connect
-
connect
-
connectWithRegex
-
patch
-
patch
-
patchWithRegex
-
getRoutes
-
clear
Router clear()Remove all the routes from this router- Returns:
- a reference to this, so the API can be used fluently
-
errorHandler
Specify an handler to handle an error for a particular status code. You can use to manage general errors too using status code 500. The handler will be called when the context fails and other failure handlers didn't write the reply or when an exception is thrown inside an handler. You must not useRoutingContext.next()inside the error handler This does not affect the normal failure routing logic.- Parameters:
statusCode- status code the errorHandler is capable of handleerrorHandler- error handler. Note: You must not useRoutingContext.next()inside the provided handler- Returns:
- a reference to this, so the API can be used fluently
-
uncaughtErrorHandler
Specify an handler to handle an error for any status code that doesn't have a specific handler assigned. The handler will be called when the context fails and other failure handlers didn't write the reply or when an exception is thrown inside an handler. You must not useRoutingContext.next()inside the error handler This does not affect the normal failure routing logic.- Parameters:
errorHandler- error handler. Note: You must not useRoutingContext.next()inside the provided handler- Returns:
- a reference to this, so the API can be used fluently
-
handleContext
Used to route a context to the router. Used for sub-routers. You wouldn't normally call this method directly.- Parameters:
context- the routing context
-
handleFailure
Used to route a failure to the router. Used for sub-routers. You wouldn't normally call this method directly.- Parameters:
context- the routing context
-
modifiedHandler
When a Router routes are changed this handler is notified. This is useful for routes that depend on the state of the router.- Parameters:
handler- a notification handler that will receive this router as argument- Returns:
- a reference to this, so the API can be used fluently
-
allowForward
Set whether the router should parse "forwarded"-type headers- Parameters:
allowForwardHeaders- to enable parsing of "forwarded"-type headers- Returns:
- a reference to this, so the API can be used fluently
-