goophi.routing
compile-pattern
(compile-pattern pattern)
Compiles a pattern. Patterns may consist of literals, escaped
characters, wildcards (*) and parameters (:name). The syntax is
very similar to to Clout (https://github.com/weavejester/clout).
That's no surprise, because the code is similar too :)
matches
(matches route request)
Tests if request is matching the pattern associated to route.
Returns a map containing path, query and matched parameters on
success.
route
macro
(route pattern vars & body)
Returns a function that takes a request map as argument. The function
evaluates body and returns the value of the expression if pattern is
matching the request path. Parameters are bound to vars.
Example:
(route
"/blog/posts/:id"
[id]
(get-post id))
Use the :as keyword to assign the entire request map to a symbol.
Example:
(route
"/blog/:category/search"
[category :as req]
(search-category category (:query req)))
routes
macro
(routes & routes)
Returns a function that takes a request map as argument. The function
evaluates the body of the first route matching the request path and
returns the value of the expression. Parameters are bound to vars.
Example:
(routes
("/blog/posts/:id"
[id]
(get-post id))
("/blog/:category/search"
[category :as req]
(search-category category (:query req))))