Skip to content

Fast, 2-way, generic URL routing library for use by Clojure web frameworks

License

Notifications You must be signed in to change notification settings

mmcgrana/clj-routing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clj-routing is a library for implementing fast, 2-way URL routing in Clojure web applications.

The library allows you to separate the core routing implementation (handled by clj-routing) from the interface or DSL for describing routes (typically handled by a web framework).

Usage

(use 'clj-routing.core)

(def routes
  [[:index-bars  :get "/foo/bars"                         ]
   [:show-bar    :get "/foo/bars/:id"                     ]
   [:create-bat  :put "/foo/bars"                         ]
   [:with-conds  :get "/foo/:action" {:action "biz|bats"} ]
   [:catch-all   :any "/:path"       {:path   ".*"}       ]])

(def generate  (compiled-generator  routes))
(def recognize (compiled-recognizer routes))

(generate :index-bars)
=> [:get "/foo/bars" nil]

(generate :show-bar {:id "theid"})
=> [:get "/foo/bars/theid" {}]

(generate :show-bar {:id "theid" :more "extra"})
=> [:get "/foo/bars/theid" {:more "extra"}]

(generate :show-bar)
=> Exception: "Missing param: :id"

(generate :foo-bar)
=> Exception: "Unrecognized route name: :foo-bar" 

(recognize :get "/foo/bars")
=> [:index-bars {}]

(recognize :get "/foo/bars/bat")
=> [:show-bar {:id "bat"}]

(recognize :get "/foo/biz")
=> [:with-conds {:action "biz"}]

(recognize :get "/foo/fiz")
=> [:catch-all {:path "foo/fiz"}]

(recognize :foo "/foo/bars")
=> Exception: "Unrecognized method: :foo"

Please see the clj-routing.core docstring and the clj-routing.core-test code for additional documentation.

License

Copyright (c) 2009 Mark McGranaghan and released under an MIT license.

About

Fast, 2-way, generic URL routing library for use by Clojure web frameworks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published