Package core :: Module http :: Class RouteMatcher
[hide private]
[frames] | no frames]

Class RouteMatcher

source code

object --+
         |
        RouteMatcher

This class allows you to do route requests based on the HTTP verb and the request URI, in a manner similar to <a href="http://www.sinatrarb.com/">Sinatra</a> or <a href="http://expressjs.com/">Express</a>.

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.

Instance Methods [hide private]
 
__init__(self) source code
 
__call__(self, data) source code
 
input(self, request)
This method is called to provide the matcher with data.
source code
 
get(self, pattern, handler)
Specify a handler that will be called for a matching HTTP GET
source code
 
put(self, pattern, handler)
Specify a handler that will be called for a matching HTTP PUT
source code
 
post(self, pattern, handler)
Specify a handler that will be called for a matching HTTP POST
source code
 
delete(self, pattern, handler)
Specify a handler that will be called for a matching HTTP DELETE
source code
 
options(self, pattern, handler)
Specify a handler that will be called for a matching HTTP OPTIONS
source code
 
head(self, pattern, handler)
Specify a handler that will be called for a matching HTTP HEAD
source code
 
trace(self, pattern, handler)
Specify a handler that will be called for a matching HTTP TRACE
source code
 
patch(self, pattern, handler)
Specify a handler that will be called for a matching HTTP PATCH
source code
 
connect(self, pattern, handler)
Specify a handler that will be called for a matching HTTP CONNECT
source code
 
all(self, pattern, handler)
Specify a handler that will be called for any matching HTTP request
source code
 
get_re(self, pattern, handler)
Specify a handler that will be called for a matching HTTP GET
source code
 
put_re(self, pattern, handler)
Specify a handler that will be called for a matching HTTP PUT
source code
 
post_re(self, pattern, handler)
Specify a handler that will be called for a matching HTTP POST
source code
 
delete_re(self, pattern, handler)
Specify a handler that will be called for a matching HTTP DELETE
source code
 
options_re(self, pattern, handler)
Specify a handler that will be called for a matching HTTP OPTIONS
source code
 
head_re(self, pattern, handler)
Specify a handler that will be called for a matching HTTP HEAD
source code
 
trace_re(self, pattern, handler)
Specify a handler that will be called for a matching HTTP TRACE
source code
 
patch_re(self, pattern, handler)
Specify a handler that will be called for a matching HTTP PATCH
source code
 
connect_re(self, pattern, handler)
Specify a handler that will be called for a matching HTTP CONNECT
source code
 
all_re(self, pattern, handler)
Specify a handler that will be called for any matching HTTP request
source code
 
no_match(self, handler)
Specify a handler that will be called when nothing matches Default behaviour is to return a 404
source code
Method Details [hide private]

__init__(self)
(Constructor)

source code 
Overrides: object.__init__
(inherited documentation)

input(self, request)

source code 

This method is called to provide the matcher with data.

Keyword arguments:

Parameters:
  • request - input request to the parser.

get(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - handler for match

put(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

post(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

delete(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

options(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

head(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

trace(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

patch(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

connect(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

all(self, pattern, handler)

source code 

Specify a handler that will be called for any matching HTTP request

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

get_re(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

put_re(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

post_re(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

delete_re(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

options_re(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

head_re(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

trace_re(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

patch_re(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

connect_re(self, pattern, handler)

source code 

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

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

all_re(self, pattern, handler)

source code 

Specify a handler that will be called for any matching HTTP request

Keyword arguments:

Parameters:
  • pattern - pattern to match
  • handler - http server request handler

no_match(self, handler)

source code 

Specify a handler that will be called when nothing matches Default behaviour is to return a 404

Keyword arguments:

Parameters:
  • handler - http server request handler