Skip to content

Instantly share code, notes, and snippets.

@rlander
Last active October 2, 2019 14:48
Show Gist options
  • Save rlander/a0375b06f2b92b3298c67c43352776a5 to your computer and use it in GitHub Desktop.
Save rlander/a0375b06f2b92b3298c67c43352776a5 to your computer and use it in GitHub Desktop.
(ns myapi.interceptors)
(def user-auth
{:before (fn [context]
(update-in context :password h/encrypt-password))
:after (fn [context]
(dissoc context [:password]))})
(def interceptors [user-auth])
(ns myapi.routes)
(def routes
(start-server ...
(mount ::myapi.my-service ::myapi.interceptors)))
(ns myapi.services)
(defn fetch [id params]
(db/select-one id params))
(defn fetch* [params]
(db/select params))
(defn create! [data params]
(db/insert! data params))
@rlander
Copy link
Author

rlander commented Oct 2, 2019

Using services with full interceptors:

(with-hooks [::myapi.interceptors]
  (create! {:username "Fulano" :password "segredo"}))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment