new RouteMatcher()
This class allows you to do route requests based on the HTTP verb and the request URI, in a manner similar to Sinatra or Express. RouteMatcher also lets you extract paramaters from the request URI either a simple pattern or using regular expressions for more complex matches. Any parameters extracted will be added to the requests parameters which will be available to you in your request handler.
It's particularly useful when writing REST-ful web applications.
To use a simple pattern to extract parameters simply prefix the parameter name in the pattern with a ':' (colon).
Different handlers can be specified for each of the HTTP verbs, GET, POST, PUT, DELETE etc.
For more complex matches regular expressions can be used in the pattern. When regular expressions are used, the extracted parameters do not have a name, so they are put into the HTTP request with names of param0, param1, param2 etc.
Multiple matches can be specified for each HTTP verb. In the case there are more than one matching patterns for a particular request, the first matching one will be used.- Source:
Example
var http = require('vertx/http');
var server = http.createHttpServer();
var routeMatcher = new http.RouteMatcher();
routeMatcher.get('/animals/dogs', function(req) {
req.response.end('You requested dogs');
});
routeMatcher.get('/animals/cats', function(req) {
req.response.end('You requested cats');
});
server.requestHandler(routeMatcher).listen(8080, 'localhost');
Methods
-
all(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP ALL
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
allWithRegEx(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP request
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
connect(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP CONNECT
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
connectWithRegEx(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP CONNECT
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
delete(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP DELETE
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
deleteWithRegEx(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP DELETE
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
get(handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP GET
Parameters:
Name Type Description handler
RequestHandler handler for match - Source:
Returns:
-
getWithRegEx(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP GET
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
head(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP HEAD
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
headWithRegEx(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP HEAD
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
noMatch(handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for HTTP request that not match any pattern.
Parameters:
Name Type Description handler
RequestHandler http server request handler - Source:
Returns:
-
options(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP OPTIONS
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
optionsWithRegEx(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP PUT
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
patch(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP PATCH
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
patchWithRegEx(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP PATCH
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
post(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP POST
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
postWithRegEx(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP POST
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
put(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP PUT
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
putWithRegEx(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP PUT
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
trace(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP TRACE
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns:
-
traceWithRegEx(pattern, handler) → {module:vertx/http.RouteMatcher}
-
Specify a handler that will be called for a matching HTTP TRACE
Parameters:
Name Type Description pattern
string pattern to match handler
RequestHandler http server request handler - Source:
Returns: