weavejester / clout
- Source
- Commits
- Network (1)
- Issues (0)
- Downloads (1)
- Wiki (1)
- Graphs
-
Tree:
2c3fc4f
commit 2c3fc4f437d64d1c0285f2abbc9faab4a578b719
tree fd5e84e4b65d7a1ce3c5c78df2ba0f38e7c3f495
parent fad8af4c176f4babc1af42ae872b964420d1da8d
tree fd5e84e4b65d7a1ce3c5c78df2ba0f38e7c3f495
parent fad8af4c176f4babc1af42ae872b964420d1da8d
clout /
| name | age | message | |
|---|---|---|---|
| |
README.markdown | ||
| |
src/ |
README.markdown
Clout
Clout is a library for matching HTTP routes in Clojure. It uses the same routing syntax as used by popular Ruby web frameworks like Ruby on Rails and Sinatra.
Here is an example of use:
user=> (use 'clout)
nil
user=> (route-matches "/article/:title" "/article/clojure")
{:title "clojure"}
user=> (route-matches "/public/*" "/public/style/screen.css")
{:* "style/screen.css"}
Clout supports both keywords and wildcards. Keywords (like ":title") will
match any character but the following: / . , ; ?. Wildcards will match
anything.
If a route does not match, nil is returned:
user=> (route-matches "/products" "/articles")
nil
For additional performance you can choose to pre-compile routes:
user=> (def user-route (route-compile "/user/:id"))
#'user/user-route
user=> (route-matches user-route "/user/10")
{:user "10"}
When compiling a route, you can specify a map of regular expressions to use for different keywords. This allows more specific routing:
user=> (def user-route (route-compile "/user/:id" {:id #"\d+"}))
#'user/user-route
user=> (route-matches user-route "/user/10")
{:user "10"}
user=> (route-matches user-route "/user/jsmith")
nil

