This file contains hidden or 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
(def app | |
(-> handler | |
(wrap-keyword-params) | |
(wrap-params))) |
This file contains hidden or 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 blog-ring.middleware | |
(:require [ring.middleware.params :refer [wrap-params]] | |
[ring.middleware.keyword-params :refer [wrap-keyword-params]])) | |
((wrap-params identity) | |
{:query-string "clojure=yes&lisp=maybe"}) | |
;; -> {:query-string "clojure=yes&lisp=maybe", | |
;; :form-params {}, | |
;; :params {"clojure" "yes", "lisp" "maybe"}, | |
;; :query-params {"clojure" "yes", "lisp" "maybe"}} |
This file contains hidden or 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
(defn handler [request] | |
{:status 200 | |
:headers {"Content-Type" "text/html"} | |
:body (str "<h1>One Ring rules them all!</h1>" | |
"<ul><li>Request from IP: " | |
(:remote-addr request) | |
"</li><li>Request method: " | |
(:request-method request) | |
"</li><li>Headers: " | |
(select-keys |
This file contains hidden or 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 blog-ring.response | |
(:require [ring.util.response :as res])) | |
(def simple-res (res/response "Hello, world!")) | |
simple-res | |
;; -> {:status 200, | |
;; :headers {}, | |
;; :body "Hello, world!"} |
This file contains hidden or 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 blog-ring "0.1.0-SNAPSHOT" | |
:dependencies [[org.clojure/clojure "1.8.0"] | |
[ring "1.6.0-RC2"]] | |
:main blog-ring.core) |
This file contains hidden or 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 blog-ring.core | |
(:require [ring.adapter.jetty :as jetty])) | |
(defn handler [request] | |
{:status 200 | |
:headers {"Content-Type" "text/html"} | |
:body "<h1>Hello, world!</h1>"}) | |
(defn -main [] | |
(jetty/run-jetty handler |
This file contains hidden or 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
(defn spicy [first second third] | |
(println "I like food with" first "," second "and" third ".")) | |
(def curry-and-chilli | |
(partial spicy "curry" "curry" "chilli")) | |
(curry-and-chilli) | |
;; -> I like food with curry , curry and chilli . |
This file contains hidden or 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
(defn spicy [first second third] | |
(println "I like food with" first "," second "and" third ".")) | |
(def curry (partial spicy "curry")) | |
(def more-curry (partial curry "curry")) | |
(def curry-and-chilli (partial more-curry "chilli")) | |
(curry-and-chilli) |
This file contains hidden or 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
def spicy = { first, second, third -> | |
println "I like food with $first, $second and $third." | |
} | |
def curry = spicy.curry("curry") | |
def moreCurry = curry.curry("curry") | |
def curryAndChilli = moreCurry.curry("chilli") | |
curryAndChilli.call() | |
// prints: |
This file contains hidden or 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
;; the initial namespace in REPL is 'user' | |
(def my-var "var in the user namespace") | |
(ns new-namespace) | |
my-var | |
;; -> CompilerException java.lang.RuntimeException: | |
;; Unable to resolve symbol: my-var in this context |