Skip to content

r0man/routes-clj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

routes-clj

https://travis-ci.org/r0man/routes-clj.svg http://jarkeeper.com/r0man/routes-clj/status.svg http://jarkeeper.com/r0man/routes-clj/downloads.svg

Installation

https://clojars.org/routes-clj/latest-version.svg

Usage

Require the library.

(require '[routes.core :refer :all])

Define routes by passing vectors of route pattern and route names do defroutes.

(defroutes my-routes
  ["/countries" :countries]
  ["/countries/:id-:name" :country]
  ["/spots" :spots]
  ["/spots/:id-:name" :spot])

Build URL paths by route name.

(path-for :countries)
"/countries"
(path-for :country {:id 1 :name "Spain"})
"/countries/1-Spain"

Build URL by route name.

(def server
  {:scheme :https
   :server-name "example.com"
   :server-port 443})
(url-for server :countries)
"https://example.com/countries"
(url-for server :country {:id 1 :name "Spain"})
"https://example.com/countries/1-Spain"

Build Ring request maps by route name.

(request-for server :countries {:query-params {:sort "asc"}})
{:uri "/countries", :query-params {:sort "asc"}, :server-port 443, :server-name "example.com", :scheme :https, :request-method :get}

License

Copyright © 2012-2015 r0man

Distributed under the Eclipse Public License, the same as Clojure.

About

A Clojure & ClojureScript library to build url and path fns.

Resources

Stars

Watchers

Forks

Packages

No packages published