GLOBAL INDEX  |  FRAMES  |  NO FRAMES
Library: dispatching
Overview
Helper functions for path-based dispatching of the request.
source: dispatching.js
Functions
dispatch(opts)
Converts the path into a function name and calls that function. The function name is by replacing '/' characters in the path with underscores, and prepending the request method (get or post). For requests that end in '/', you can optionally suffix your function name with 'main'.
parameters
object opts? (optional) if opts.custom404 is a function, then this function will be called if there is no function corresponding to the request path. If opts is is not specified, a default 404 handler displays "404 not found".
examples
function get_main() {
  // called with user visits http://appname.appjet.net/
  print("hello");
}
function get_page() {
  // called with user visits http://appname.appjet.net/page
}
function post_foo() {
  // called when user POSTs to http://appname.appjet.net/foo
}
dispatch(); // examines request and calls one of the above functions.
patternDispatch(pattern1, pattern2, patternN, optional404)
Similar to dispatch(), but you provide your own mapping of regular expresions to functions.
parameters
array pattern1 array of [regexp, method]
array pattern2 array of [regexp, method]
array patternN ...
function optional404? called if none of the previous patterns match
examples
function handleIndex() {
  print("this is the main landing page");
}
function handleFoo() {
  print("this is the foo page");
}
function unknown() {
  response.setStatusCode(404);
  print("path not found: ", request.path);
}
patternDispatch(
  [/^\/$/, handleIndex],
  [/^\/foo$/, handleFoo],
  unknown
);
Generated by JsDoc Toolkit 1.3.3 on Thu, 03 Jul 2008 01:27:42 GMT.