Skip to content

Instantly share code, notes, and snippets.

@zehnpaard
Created October 25, 2016 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zehnpaard/6143195e47adaa0a73b174cdb7252983 to your computer and use it in GitHub Desktop.
Save zehnpaard/6143195e47adaa0a73b174cdb7252983 to your computer and use it in GitHub Desktop.
Minimal Ring App with Request/Response Log
(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}))
(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