Closed niwinz closed 9 years ago
The proposal is do something like this:
;; Using protocols (def myresource (reify IResource IResourceIndex (-index [context] (http/ok "foobar")) IResourceShow (-show [context] (http/ok "foobar")) IResourceCreate (-create [context] (http/created "foobar")) IResourceUpdate (-update [context] (http/ok "foobar")) IResourceDelete (-delete [context] (http/ok "foobar")))) ;; Using multimethods (defmulti myresource (fn [type context] type)) (defmethod myresource :index [_ context] (http/ok "foobar")) (defmethod myresource :show [_ context] (http/ok "foobar")) (defmethod myresource :create [_ context] (http/ok "foobar")) (defmethod myresource :update [_ context] (http/ok "foobar")) (defmethod myresource :delete [_ context] (http/ok "foobar")) ;; Using plain functions and hash-maps (defn index [contex] (http/ok "foobar")) (defn show [contex] (http/ok "foobar")) (defn create [contex] (http/ok "foobar")) (defn update [contex] (http/ok "foobar")) (defn delete [contex] (http/ok "foobar")) (def myresource {:index index :show show :create create :update update :delete delete})
And it will be used in this way:
(require '[catacumba.handlers.restfull :as rest]) (ct/routes [[:prefix "api/v1" (rest/resource "authors" myauthorresource) (rest/resource "books" mybooksresource)]])
Already implemented in master ;)
The proposal is do something like this:
And it will be used in this way: