Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Learning Clojure

Ring

  • Adapater Http Request -> Ring Request Ring Resposne -> Http Response
  • Handler Ring Request -> Http Response Basically clojure function
(defn handler [req]
  {:status: 200
   :body "Hello, world!"
   :headers {}})
  • Middleware Handler + Options -> Handler
(defn mw [hdlr & options]
  (fn [req]
    (hdlr (modify req)))
(defn mw [hdlr & options]
  (fn [req]
    (modify (hdlr req)))
(defn mw [hdlr & options]
  (fn [req]
    (do-something)
    (hdlr req))

Ring CheatSheet

Compojure

  • Routing Path + Http Method route to specific Handler
(defroute rotues
  (Get "/" [] home-handler)
    ...
  (not-found "Page not found."))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.