Last active
February 19, 2020 17:17
-
-
Save rgm/775909ca19002591c8952b823327558d to your computer and use it in GitHub Desktop.
partially-applied handler example for https://clojurians.slack.com/archives/CKKPVDX53/p1582074246024200
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
(defn my-regular-handler | |
[req] | |
{:status 200 :headers {} :body []}) | |
(defn my-resource-handler | |
[datasource req] | |
(let [foo (do-something-with-datasource datasource req)] | |
{:status 200 :headers {} :body foo})) | |
(defn make-top-level-handler | |
[datasource] | |
(reitit.ring/ring-handler | |
(reitit.ring/router | |
[["/" {:get {:handler my-regular-handler}}] | |
["/get-thing" {:get {:handler (partial my-resource-handler datasource)}}]]) | |
(reitit.ring/routes | |
(reitit.ring/create-resource-handler {:path "/"}) | |
(reitit.ring/create-default-handler)) | |
{:middleware [,,,]})) | |
(defmethod ig/init-key ::app | |
[_ {:keys [datasource]}] | |
(make-top-level-handler datasource)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment