Package io.vertx.ext.web
Interface Router
-
- All Superinterfaces:
Handler<HttpServerRequest>
public interface Router extends Handler<HttpServerRequest>
A router receives request from anHttpServer
and routes it to the first matchingRoute
that it contains. A router can contain many routes.Routers are also used for routing failures.
- Author:
- Tim Fox
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Router
allowForward(AllowForwardHeaders allowForwardHeaders)
Set whether the router should parse "forwarded"-type headersRouter
clear()
Remove all the routes from this routerRoute
connect()
Add a route that matches any HTTP CONNECT requestRoute
connect(String path)
Add a route that matches a HTTP CONNECT request and the specified pathRoute
connectWithRegex(String regex)
Add a route that matches a HTTP CONNECT request and the specified path regexRoute
delete()
Add a route that matches any HTTP DELETE requestRoute
delete(String path)
Add a route that matches a HTTP DELETE request and the specified pathRoute
deleteWithRegex(String regex)
Add a route that matches a HTTP DELETE request and the specified path regexRouter
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 requestRoute
get(String path)
Add a route that matches a HTTP GET request and the specified pathdefault <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 regexvoid
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 requestRoute
head(String path)
Add a route that matches a HTTP HEAD request and the specified pathRoute
headWithRegex(String regex)
Add a route that matches a HTTP HEAD request and the specified path regexMap<String,Object>
metadata()
Router
modifiedHandler(Handler<Router> handler)
When a Router routes are changed this handler is notified.Route
options()
Add a route that matches any HTTP OPTIONS requestRoute
options(String path)
Add a route that matches a HTTP OPTIONS request and the specified pathRoute
optionsWithRegex(String regex)
Add a route that matches a HTTP OPTIONS request and the specified path regexRoute
patch()
Add a route that matches any HTTP PATCH requestRoute
patch(String path)
Add a route that matches a HTTP PATCH request and the specified pathRoute
patchWithRegex(String regex)
Add a route that matches a HTTP PATCH request and the specified path regexRoute
post()
Add a route that matches any HTTP POST requestRoute
post(String path)
Add a route that matches a HTTP POST request and the specified pathRoute
postWithRegex(String regex)
Add a route that matches a HTTP POST request and the specified path regexRoute
put()
Add a route that matches any HTTP PUT requestRoute
put(String path)
Add a route that matches a HTTP PUT request and the specified pathRouter
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 regexRoute
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 pathRoute
route(String path)
Add a route that matches the specified pathstatic Router
router(Vertx vertx)
Create a routerRoute
routeWithRegex(HttpMethod method, String regex)
Add a route that matches the specified HTTP method and path regexRoute
routeWithRegex(String regex)
Add a route that matches the specified path regexRoute
trace()
Add a route that matches any HTTP TRACE requestRoute
trace(String path)
Add a route that matches a HTTP TRACE request and the specified pathRoute
traceWithRegex(String regex)
Add a route that matches a HTTP TRACE request and the specified path regex
-
-
-
Method Detail
-
putMetadata
Router putMetadata(String key, Object value)
Put metadata to this router. Used for saved extra data. Remove the existing value if value is null.- Parameters:
key
- the metadata of keyvalue
- the metadata of value- Returns:
- a reference to this, so the API can be used fluently
-
getMetadata
default <T> T getMetadata(String key)
Get some data from metadata.- Type Parameters:
T
- the type of the data- Parameters:
key
- the key for the metadata- Returns:
- the data
-
router
static Router router(Vertx vertx)
Create a router- Parameters:
vertx
- the Vert.x instance- Returns:
- the router
-
route
Route route()
Add a route with no matching criteria, i.e. it matches all requests or failures.- Returns:
- the route
-
route
Route route(HttpMethod method, String path)
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
Route route(String path)
Add a route that matches the specified path- Parameters:
path
- URI paths that begin with this path will match- Returns:
- the route
-
routeWithRegex
Route routeWithRegex(HttpMethod method, String regex)
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
Route routeWithRegex(String regex)
Add a route that matches the specified path regex- Parameters:
regex
- URI paths that begin with a match for this regex will match- Returns:
- the route
-
get
Route get()
Add a route that matches any HTTP GET request- Returns:
- the route
-
get
Route get(String path)
Add a route that matches a HTTP GET request and the specified path- Parameters:
path
- URI paths that begin with this path will match- Returns:
- the route
-
getWithRegex
Route getWithRegex(String regex)
Add a route that matches a HTTP GET request and the specified path regex- Parameters:
regex
- URI paths that begin with a match for this regex will match- Returns:
- the route
-
head
Route head()
Add a route that matches any HTTP HEAD request- Returns:
- the route
-
head
Route head(String path)
Add a route that matches a HTTP HEAD request and the specified path- Parameters:
path
- URI paths that begin with this path will match- Returns:
- the route
-
headWithRegex
Route headWithRegex(String regex)
Add a route that matches a HTTP HEAD request and the specified path regex- Parameters:
regex
- URI paths that begin with a match for this regex will match- Returns:
- the route
-
options
Route options()
Add a route that matches any HTTP OPTIONS request- Returns:
- the route
-
options
Route options(String path)
Add a route that matches a HTTP OPTIONS request and the specified path- Parameters:
path
- URI paths that begin with this path will match- Returns:
- the route
-
optionsWithRegex
Route optionsWithRegex(String regex)
Add a route that matches a HTTP OPTIONS request and the specified path regex- Parameters:
regex
- URI paths that begin with a match for this regex will match- Returns:
- the route
-
put
Route put()
Add a route that matches any HTTP PUT request- Returns:
- the route
-
put
Route put(String path)
Add a route that matches a HTTP PUT request and the specified path- Parameters:
path
- URI paths that begin with this path will match- Returns:
- the route
-
putWithRegex
Route putWithRegex(String regex)
Add a route that matches a HTTP PUT request and the specified path regex- Parameters:
regex
- URI paths that begin with a match for this regex will match- Returns:
- the route
-
post
Route post()
Add a route that matches any HTTP POST request- Returns:
- the route
-
post
Route post(String path)
Add a route that matches a HTTP POST request and the specified path- Parameters:
path
- URI paths that begin with this path will match- Returns:
- the route
-
postWithRegex
Route postWithRegex(String regex)
Add a route that matches a HTTP POST request and the specified path regex- Parameters:
regex
- URI paths that begin with a match for this regex will match- Returns:
- the route
-
delete
Route delete()
Add a route that matches any HTTP DELETE request- Returns:
- the route
-
delete
Route delete(String path)
Add a route that matches a HTTP DELETE request and the specified path- Parameters:
path
- URI paths that begin with this path will match- Returns:
- the route
-
deleteWithRegex
Route deleteWithRegex(String regex)
Add a route that matches a HTTP DELETE request and the specified path regex- Parameters:
regex
- URI paths that begin with a match for this regex will match- Returns:
- the route
-
trace
Route trace()
Add a route that matches any HTTP TRACE request- Returns:
- the route
-
trace
Route trace(String path)
Add a route that matches a HTTP TRACE request and the specified path- Parameters:
path
- URI paths that begin with this path will match- Returns:
- the route
-
traceWithRegex
Route traceWithRegex(String regex)
Add a route that matches a HTTP TRACE request and the specified path regex- Parameters:
regex
- URI paths that begin with a match for this regex will match- Returns:
- the route
-
connect
Route connect()
Add a route that matches any HTTP CONNECT request- Returns:
- the route
-
connect
Route connect(String path)
Add a route that matches a HTTP CONNECT request and the specified path- Parameters:
path
- URI paths that begin with this path will match- Returns:
- the route
-
connectWithRegex
Route connectWithRegex(String regex)
Add a route that matches a HTTP CONNECT request and the specified path regex- Parameters:
regex
- URI paths that begin with a match for this regex will match- Returns:
- the route
-
patch
Route patch()
Add a route that matches any HTTP PATCH request- Returns:
- the route
-
patch
Route patch(String path)
Add a route that matches a HTTP PATCH request and the specified path- Parameters:
path
- URI paths that begin with this path will match- Returns:
- the route
-
patchWithRegex
Route patchWithRegex(String regex)
Add a route that matches a HTTP PATCH request and the specified path regex- Parameters:
regex
- URI paths that begin with a match for this regex will match- Returns:
- the route
-
clear
Router clear()
Remove all the routes from this router- Returns:
- a reference to this, so the API can be used fluently
-
errorHandler
Router errorHandler(int statusCode, Handler<RoutingContext> 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
-
handleContext
void handleContext(RoutingContext context)
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
void handleFailure(RoutingContext context)
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
Router modifiedHandler(Handler<Router> handler)
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
Router allowForward(AllowForwardHeaders allowForwardHeaders)
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
-
-