Skip to content

Instantly share code, notes, and snippets.

@kafaichoi
Created September 14, 2017 06:38
Show Gist options
  • Save kafaichoi/0ca3864bc144b4ecd1f81fd6f5c699a5 to your computer and use it in GitHub Desktop.
Save kafaichoi/0ca3864bc144b4ecd1f81fd6f5c699a5 to your computer and use it in GitHub Desktop.
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