Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update README.

  • Loading branch information...
commit ddff915c1fb68abd97cf0674b2309b00f6ad010f 1 parent 8bdfbe9
Martin authored May 19, 2009

Showing 1 changed file with 76 additions and 0 deletions. Show diff stats Hide diff stats

  1. 76  README
76  README
... ...
@@ -0,0 +1,76 @@
  1
+Small and simple standalone router, meant for use with Rack applications.
  2
+
  3
+PROBLEMS/FEATURES
  4
+o Familiar Sinatra-like DSL for defining actions
  5
+o Modular architecture (see ROUTING ENGINES section)
  6
+o No magic
  7
+o Low level / Highly flexible
  8
+o Simple code
  9
+
  10
+
  11
+EXAMPLES
  12
+class App
  13
+  include SimpleRouter::DSL
  14
+
  15
+  get '/' do
  16
+    'home'
  17
+  end
  18
+
  19
+  get '/archives/:year/:month/:day' do |year, month, day|
  20
+    Article.archived.find_by_date(year, month, day)
  21
+  end
  22
+
  23
+  def call(env)
  24
+    verb, path  = ENV['REQUEST_METHOD'], ENV['PATH_INFO']
  25
+    route, args = self.class.routes.match(verb, path)
  26
+    route.nil? ?
  27
+      [404, {'Content-Type' => 'text/html'}, '404 page not found'] :
  28
+      [200, {'Content-Type' => 'text/html'}, route.action.call(*args)]
  29
+  end
  30
+end
  31
+
  32
+The SimpleRouter::DSL mixin provides 5 class methods:
  33
+
  34
+  #get, #post, #put, #delete and #routes
  35
+
  36
+The four verb methods allow you to define actions that will match a request for
  37
+the verb and route signature it defines.
  38
+
  39
+The #routes method responds to #match and will return the first matching route
  40
+(in order they were defined), and the values of the variables defined in the
  41
+route signature if any (:year, :month, ...).
  42
+
  43
+Finally, the route returned is a simple object: for the second route in the
  44
+example above:
  45
+
  46
+  route.verb    = :get
  47
+  route.path    = '/archives/:year/:month/:day'
  48
+  route.action  = lambda {|year, month, day| Article.archived.find_by_date(year, month, day) }
  49
+
  50
+See examples/ directory for executable code examples.
  51
+
  52
+
  53
+ROUTING ENGINES
  54
+By design, the code is seperated in two main components:
  55
+
  56
+  o DSL for defining routes/actions and retrieving requested action block.
  57
+  o Routing engine
  58
+
  59
+Different engines can be used by assigning them to the router:
  60
+
  61
+  SimpleRouter.engine = UltraFastEngine
  62
+
  63
+This allows, for instance, a new faster engine to be used by an app without
  64
+changes in the top level DSL.
  65
+
  66
+Engines can also allow route definitions to include more (or less!) features.
  67
+For example, the built-in SimpleEngine allows route variables and extention
  68
+handling. Others could add variable conditions ( :id => Integer ), mime-type
  69
+restrictions, etc.
  70
+
  71
+ENGINE WRITERS
  72
+Engines only need to conform to a simple interface. See the wiki for the
  73
+details. (TODO: add interface spec to wiki)
  74
+
  75
+LICENSE
  76
+MIT. See LICENSE file.

0 notes on commit ddff915

Please sign in to comment.
Something went wrong with that request. Please try again.