Created
October 25, 2016 08:38
-
-
Save zehnpaard/6143195e47adaa0a73b174cdb7252983 to your computer and use it in GitHub Desktop.
Minimal Ring App with Request/Response Log
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 ring-min-log.core | |
(require | |
[ring.util.response :as res] | |
[ring.adapter.jetty :refer [run-jetty]] | |
)) | |
(defn handler [req] | |
(-> (res/response "Hello Goodbye") | |
(res/content-type "text/plain"))) | |
(defonce log-atom (atom [])) | |
(defn logger [handler] | |
(fn [req] | |
(let [res (handler req)] | |
(swap! log-atom #(conj % {:request req :response res})) | |
res))) | |
(def my-app | |
(-> handler | |
logger)) | |
(defonce server (run-jetty #'my-app {:port 8080 :join? false})) |
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
(defproject ring-min-log "0.1.0-SNAPSHOT" | |
:dependencies [[org.clojure/clojure "1.8.0"] | |
[ring "1.5.0"]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment