Class: RouteMatcher

vertx/http. RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher

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:
Type
module:vertx/http.RouteMatcher