Created
August 28, 2009 11:57
-
-
Save Licenser/176928 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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