Skip to content

Instantly share code, notes, and snippets.

@stathissideris
Last active September 26, 2016 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stathissideris/e6c402c6b9c48cd5cb140cd64ebd79ff to your computer and use it in GitHub Desktop.
Save stathissideris/e6c402c6b9c48cd5cb140cd64ebd79ff to your computer and use it in GitHub Desktop.
bidi verbose
(defn leaf [fragment name]
[fragment name])
(defn branch [fragment & children]
(let [[[tag param]] children]
(if (= tag :bidi/param)
[[fragment param] (vec (rest children))]
[fragment (vec children)])))
(defn param [name]
[:bidi/param name])
(def routes
(branch
"http://localhost:8080"
(branch "/users/" (param :user-id)
(branch "/topics"
(leaf "" :topics)
(leaf "/bulk" :topic-bulk)))
(branch "/topics/" (param :topic)
(leaf "" :private-topic))
(leaf "/schemas" :schemas)
(branch "/orgs/" (param :org-id)
(leaf "/topics" :org-topics))))
;;compiles to:
;; ["http://localhost:8080"
;; [[["/users/" :user-id]
;; [["/topics" [["" :topics] ["/bulk" :topic-bulk]]]]]
;; [["/topics/" :topic] [["" :private-topic]]]
;; ["/schemas" :schemas]
;; [["/orgs/" :org-id] [["/topics" [["" :org-topics]]]]]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment