arango-cljs / forest

Clojurescript library to interact with ArangoDB inside Foxx context
http://arango-cljs.github.io/forest/0.2.0/index.html
3 stars 0 forks source link

Sample app utilizing Compojure-like syntax #2

Closed myguidingstar-zz closed 9 years ago

myguidingstar-zz commented 10 years ago

This is a piece of code that works but need more instruction.

(defn my-routes [app]
  (GET app "/format" []
       {path :path {:as headers} :headers}
       (edn [path headers]))
  (GET app "/hello/:name" [name] {}
       (edn {:name name
             :version "basic url param"}))
  (GET app "/hello-destructuring/:name" [name] {}
       (edn 200 {:name name
                 :version "Hello destructuring..."}))
  (GET app "/say-hello-to-destructuring/:name" [name]
       {prot :protocol tipe :request-type}
       (edn {:name name
             :protocol prot
             :type tipe
             :version "tipe"}))
  (GET app "/say-hi-to-destructuring" []
       ;; /say-hi-to-destructuring?a=1&b=2&c=3&d=4
       {prot :protocol
        {m :a n :b :keys [c d] :as x} :parameters}
       (edn {:version "expand-handler macro"
             :all [m n c d x]}))
  (GET app "/say-yes-to-destructuring" []
       ;; /say-yes-to-destructuring?a=1&b=2&c=3&d=4
       {[a b c d] :parameters}
       (edn {:version "des vector macro."
             :all [a b c d]}))
  (GET app "/say-aloha-to-destructuring" []
       ;; /say-aloha-to-destructuring?a=1&b=2&c=3&d=4
       {[a b c d :as x] :parameters}
       (edn {:version "destructruring vector with :as"
             :all [a b c d x]}))
  (PUT app "/hello-put-edn" ;; curl -H "Content-Type: application/edn" -X PUT 'http://localhost:8529/dev/hi/hello-put-edn' -d '{:foo 1 :bar 2}'
       [] {{a :foo b :bar} :edn-parameters}
       (edn {:the-parameters [a b]})))

(-> my-routes ;; (wrap-format "json")
    wrap-edn
    start)