Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web Applications in Clojure

Web Applications in Clojure

Clojure is a JVM language that makes the impossible come true: a Lisp dialect which can actually be read and used by humans. This talk will quickly introduce the Clojure language and describe how to develop web applications with it. Even if you are afraid of parentheses, you will quickly understand why a functional language like Clojure is the perfect choice for implementing web applications, especially since it fits very well with the stateless HTTP approach

Joy Heron

March 01, 2017

More Decks by Joy Heron

Other Decks in Technology


  1. Web Applications in Clojure (Parentheses are nothing to be afraid

    of) Joy Clark Functional Programming Enthusiast
  2. @iamjoyclark Clojure > Lisp Variant for the JVM > Functional

    Language > Dynamically Typed > Immutable Data Structures > Simplicity - Separation of Data and Behavior
  3. @iamjoyclark Data Structures “Hello World” 3 3.14 3/2 \a :first

    foo #“Ch.*se” (“Hello” :first) [3 4 3] { :name “Joy” :company “innoQ” } #{3 4 3}
  4. @iamjoyclark Functions (+ 1 2) > 3 (:city {:name “innoQ”

    :city “Monheim”}) > “Monheim” (map inc [1 2 3]) > (2 3 4)
  5. @iamjoyclark Functions (fn [x y] (+ x y)) (def add

    (fn [x y] (+ x y))) (defn add [x y] (+ x y))
  6. @iamjoyclark Ring: Handler (defn example-app [request] (let [name (get-in request

    [:params :name])] {:status 200
 :headers {“Content-Type” “text/plain”} :body (str “Hello, ” name “!”)}))
  7. @iamjoyclark Ring: Middleware (defn wrap-logging [handler] (fn [request] (print request)

    (let [response (handler request)] (print response) response))) webapp Java HTTP Server Ring Server Adapter middleware middleware
  8. @iamjoyclark Compojure: Routes (defroutes app-routes (GET “/” request (list-users request))

    (POST “/” {params :params :as request} (add-user request params)) (GET “/:username” [username :as request] (get-user request username)))
  9. @iamjoyclark Hiccup: Basics [:div {:id “foo”} [:span “bar”]] <div id=“foo”>

    <span>bar</span> </div> https://github.com/weavejester/hiccup
  10. @iamjoyclark Summary > Functional Language ideal for Web Apps >

    Clojure usage is increasing > Libraries vs. Frameworks > Community is healthy and welcoming