Created
April 29, 2017 16:41
-
-
Save sw-samuraj/c9a00526e7af776c6c4e0596cedbb96c to your computer and use it in GitHub Desktop.
An example of Ring responses (for a blog post).
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!"} | |
(res/charset simple-res "utf-8") | |
;; -> {:status 200, | |
;; :headers {"Content-Type" "text/plain; charset=utf-8"}, | |
;; :body "Hello, world!"} | |
(def json-res | |
(res/response "{\"id\":1,\"content\":\"Hello, World!\"}")) | |
json-res | |
;; -> {:status 200, | |
;; :headers {}, | |
;; :body "{\"id\":1,\"content\":\"Hello, World!\"}"} | |
(res/content-type json-res "application/json") | |
;; -> {:status 200, | |
;; :headers {"Content-Type" "application/json"}, | |
;; :body "{\"id\":1,\"content\":\"Hello, World!\"}"} | |
(res/not-found "Ring not found!") | |
;; -> {:status 404, | |
;; :headers {}, | |
;; :body "Ring not found!"} | |
(res/redirect "http://clojure.cz") | |
;; -> {:status 302, | |
;; :headers {"Location" "http://clojure.cz"}, | |
;; :body ""} | |
(res/set-cookie simple-res "Clojurian" "Granted") | |
;; -> {:status 200, | |
;; :headers {}, | |
;; :body "Hello, world!", | |
;; :cookies {"Clojurian" {:value "Granted"}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment