https://github.com/r0man/routes-clj
A Clojure & ClojureScript library to build url and path fns.
https://github.com/r0man/routes-clj
Last synced: 6 months ago
JSON representation
A Clojure & ClojureScript library to build url and path fns.
- Host: GitHub
- URL: https://github.com/r0man/routes-clj
- Owner: r0man
- Created: 2012-06-20T18:50:50.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2017-01-05T20:38:09.000Z (about 9 years ago)
- Last Synced: 2025-06-20T13:10:05.118Z (7 months ago)
- Language: Clojure
- Size: 133 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
Awesome Lists containing this project
README
#+title: routes-clj
#+author: roman
#+LANGUAGE: en
[[https://travis-ci.org/r0man/routes-clj][https://travis-ci.org/r0man/routes-clj.svg]]
[[http://jarkeeper.com/r0man/routes-clj][http://jarkeeper.com/r0man/routes-clj/status.svg]]
[[http://jarkeeper.com/r0man/routes-clj][http://jarkeeper.com/r0man/routes-clj/downloads.svg]]
* Installation
[[https://clojars.org/routes-clj][https://clojars.org/routes-clj/latest-version.svg]]
* Usage
Require the library.
#+BEGIN_SRC clojure :exports code :results silent
(require '[routes.core :refer :all])
#+END_SRC
Define routes by passing vectors of route pattern and route names do
=defroutes=.
#+BEGIN_SRC clojure :exports code :results silent
(defroutes my-routes
["/countries" :countries]
["/countries/:id-:name" :country]
["/spots" :spots]
["/spots/:id-:name" :spot])
#+END_SRC
Build URL paths by route name.
#+BEGIN_SRC clojure :exports both :results verbatim
(path-for :countries)
#+END_SRC
#+RESULTS:
: "/countries"
#+BEGIN_SRC clojure :exports both :results verbatim
(path-for :country {:id 1 :name "Spain"})
#+END_SRC
#+RESULTS:
: "/countries/1-Spain"
Build URL by route name.
#+BEGIN_SRC clojure :exports code :results silent
(def server
{:scheme :https
:server-name "example.com"
:server-port 443})
#+END_SRC
#+BEGIN_SRC clojure :exports both :results verbatim
(url-for server :countries)
#+END_SRC
#+RESULTS:
: "https://example.com/countries"
#+BEGIN_SRC clojure :exports both :results verbatim
(url-for server :country {:id 1 :name "Spain"})
#+END_SRC
#+RESULTS:
: "https://example.com/countries/1-Spain"
Build Ring request maps by route name.
#+BEGIN_SRC clojure :exports both :results verbatim
(request-for server :countries {:query-params {:sort "asc"}})
#+END_SRC
#+RESULTS:
: {: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.