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.

Instances of this class are not thread-safe

By: Julien Viet

no subtypes hierarchy

Initializer
RouteMatcher()
Inherited Attributes
Attributes inherited from: Object
hash, string
Methods
allshared void all(String pattern, void handle(HttpServerRequest request))

Specify a handler that will be called for all HTTP methods

Parameters:
  • pattern

    The simple pattern

  • handle

    The handler to call

allWithRegExshared void allWithRegEx(String regex, void handle(HttpServerRequest request))

Specify a handler that will be called for all HTTP methods

Parameters:
  • regex

    A regular expression

  • handle

    The handler to call

connectshared void connect(String pattern, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP CONNECT

Parameters:
  • pattern

    The simple pattern

  • handle

    The handler to call

connectWithRegExshared void connectWithRegEx(String regex, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP CONNECT

Parameters:
  • regex

    A regular expression

  • handle

    The handler to call

deleteshared void delete(String pattern, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP DELETE

Parameters:
  • pattern

    The simple pattern

  • handle

    The handler to call

deleteWithRegExshared void deleteWithRegEx(String regex, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP DELETE

Parameters:
  • regex

    A regular expression

  • handle

    The handler to call

getshared void get(String pattern, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP GET

Parameters:
  • pattern

    The simple pattern

  • handle

    The handler to call

getWithRegExshared void getWithRegEx(String regex, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP GET

Parameters:
  • regex

    A regular expression

  • handle

    The handler to call

handleshared void handle(HttpServerRequest request)
Parameters:
  • request
    • is InternalHttpServerRequest request
shared void head(String pattern, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP HEAD

Parameters:
  • pattern

    The simple pattern

  • handle

    The handler to call

headWithRegExshared void headWithRegEx(String regex, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP HEAD

Parameters:
  • regex

    A regular expression

  • handle

    The handler to call

noMatchshared void noMatch(void handle(HttpServerRequest request))

Specify a handler that will be called when no other handlers match. If this handler is not specified default behaviour is to return a 404

optionsshared void options(String pattern, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP OPTIONS

Parameters:
  • pattern

    The simple pattern

  • handle

    The handler to call

optionsWithRegExshared void optionsWithRegEx(String regex, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP OPTIONS

Parameters:
  • regex

    A regular expression

  • handle

    The handler to call

patchshared void patch(String pattern, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP PATCH

Parameters:
  • pattern

    The simple pattern

  • handle

    The handler to call

patchWithRegExshared void patchWithRegEx(String regex, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP PATCH

Parameters:
  • regex

    A regular expression

  • handle

    The handler to call

postshared void post(String pattern, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP POST

Parameters:
  • pattern

    The simple pattern

  • handle

    The handler to call

postWithRegExshared void postWithRegEx(String regex, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP POST

Parameters:
  • regex

    A regular expression

  • handle

    The handler to call

putshared void put(String pattern, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP PUT

Parameters:
  • pattern

    The simple pattern

  • handle

    The handler to call

putWithRegExshared void putWithRegEx(String regex, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP PUT

Parameters:
  • regex

    A regular expression

  • handle

    The handler to call

traceshared void trace(String pattern, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP TRACE

Parameters:
  • pattern

    The simple pattern

  • handle

    The handler to call

traceWithRegExshared void traceWithRegEx(String regex, void handle(HttpServerRequest request))

Specify a handler that will be called for a matching HTTP TRACE

Parameters:
  • regex

    A regular expression

  • handle

    The handler to call

Inherited Methods
Methods inherited from: Object
equals