Skip to content

Instantly share code, notes, and snippets.

@Licenser
Created August 28, 2009 11:57
Show Gist options
  • Save Licenser/176928 to your computer and use it in GitHub Desktop.
Save Licenser/176928 to your computer and use it in GitHub Desktop.
(ns net.licenser.clresource
(:use compojure))
(defroutes greeter
(GET "/"
(html [:h1 "Hello World"])))
(defmacro resource [name & body]
`(let [resource_name# ~name]
~@body))
(defmacro list_items [& body]
`(GET (str "/" resource_name# ".json")
(do ~@body)))
(defmacro get_item [p & body]
`(GET (str "/" resource_name# "/:id.json")
(let [~(nth p 0) (params :id)]
(do ~@body))))
(defmacro create_item [p & body]
`(PUT (str "/" resource_name# ".json")
(let [~(nth p 0) params]
(do ~@body))))
(defmacro update_item [p & body]
`(GET (str "/" resource_name# "/:id.json")
(let [
~(nth p 0) (params :id)
~(nth p 1) params]
(do ~@body))))
(defmacro delte_item [p & body]
`(DELETE (str "/" resource_name# "/:id.json")
(let [~(nth p 0) (params :id)]
(do ~@body))))
;; (defn resourceserver [config & body]
;; (run-server
;; config
;; body))
;; (macroexpand '(get_item [id] (html [:h1 (str "GET-PEOPLE " id)])))
(run-server
{:port 8080}
(resource "people"
(list_items "...")
(get_item [id])
(create_item [data])
(update_item [id data])
(delte_item [id])))
;; v- that is what I want to result in the end.
(defroutes people
(GET "/people.json"
(html [:h1 "LIST-PEOPLE"]))
(GET "/people/:id.json"
(html [:h1 (str "GET-PEOPLE " (params :id))]))
(PUT "/people/:id.json"
(html [:h1 "UPDATE-PEOPLE"]))
(POST "/people.json"
(html [:h1 "CREATE-PEOPLE"]))
(DELETE "/people/:id.json"
(html [:h1 "DELETE-PEOPLE"])))
(macroexpand-1 '(run-server {:port 8080}
"/*" (servlet greeter)
"/*" (servlet people)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment