From 20c57b3c3c2fe7a6fd5ce0c44c4bbfeeb5d09678 Mon Sep 17 00:00:00 2001 From: Taras Verhun Date: Fri, 10 Jun 2016 23:24:29 +0300 Subject: [PATCH 1/9] Initial code --- .gitignore | 3 +- examples/get-post/project.clj | 5 +++ examples/get-post/src/get_post/core.clj | 42 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 examples/get-post/project.clj create mode 100644 examples/get-post/src/get_post/core.clj diff --git a/.gitignore b/.gitignore index 249d002..4e77473 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,6 @@ pom.xml.asc bower_components *.log /kekkonen.iml -/.idea +**/.idea +**/target .classpath \ No newline at end of file diff --git a/examples/get-post/project.clj b/examples/get-post/project.clj new file mode 100644 index 0000000..2ba670c --- /dev/null +++ b/examples/get-post/project.clj @@ -0,0 +1,5 @@ +(defproject get-post "0.1.0-SNAPSHOT" + :description "Extended examples" + :dependencies [[org.clojure/clojure "1.8.0"] + [http-kit "2.1.19"] + [metosin/kekkonen "0.1.0-SNAPSHOT"]]) diff --git a/examples/get-post/src/get_post/core.clj b/examples/get-post/src/get_post/core.clj new file mode 100644 index 0000000..e67627a --- /dev/null +++ b/examples/get-post/src/get_post/core.clj @@ -0,0 +1,42 @@ +(ns get-post.core + (:require [org.httpkit.server :as server] + [plumbing.core :refer [defnk]] + [kekkonen.http :refer :all] + [kekkonen.cqrs :as cqrs] + [kekkonen.core :as k])) + +(defnk ^:get-post get-and-post + "handles both" + {:responses {:default {:schema {:message String}}}} + [data1 data2 #_[:data name :- String] request] + (clojure.pprint/pprint request) + (if (= (:request-method request) :get) + (cqrs/success {:message (str "Hello GET, " name)}) + (cqrs/success {:message (str "Hello POST, " name)}))) + +(def app (http-api {:core {:handlers {:api [#'get-and-post]} + :type-resolver (k/type-resolver :get :get-post :post)} + :ring {:types {:get-post {:methods #{:get :post} + ; :query-params comes from Ring https://github.com/ring-clojure/ring/wiki/Parameters + :parameters {[:data1] [:request :query-params] + [:data2] [:request :body-params]}}}}})) + +(defonce server (atom nil)) + +(defn stop-server [] + (when-not (nil? @server) + ;; graceful shutdown: wait 100ms for existing requests to be finished + ;; :timeout is optional, when no timeout, stop immediately + (@server :timeout 100) + (reset! server nil))) + +(defn -main [&args] + ;; The #' is useful when you want to hot-reload code + ;; You may want to take a look: https://github.com/clojure/tools.namespace + ;; and http://http-kit.org/migration.html#reload + (reset! server (server/run-server #'app {:port 3000})) + (println "server running in port 3000")) + +(defn run-server [] + (reset! server (server/run-server #'app {:port 3000})) + (println "server running in port 3000")) \ No newline at end of file From 01b72deb4286a63819d4792b565d0309435f2ba0 Mon Sep 17 00:00:00 2001 From: Taras Verhun Date: Sat, 11 Jun 2016 00:21:54 +0300 Subject: [PATCH 2/9] simple but OK version --- examples/get-post/src/get_post/core.clj | 37 +++++++++++++++++-------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/examples/get-post/src/get_post/core.clj b/examples/get-post/src/get_post/core.clj index e67627a..df28961 100644 --- a/examples/get-post/src/get_post/core.clj +++ b/examples/get-post/src/get_post/core.clj @@ -3,37 +3,50 @@ [plumbing.core :refer [defnk]] [kekkonen.http :refer :all] [kekkonen.cqrs :as cqrs] - [kekkonen.core :as k])) + [kekkonen.core :as k] + [schema.core :as s])) + +(s/defschema GetInput + {:name s/Str + (s/optional-key :description) s/Str}) + +(s/defn get-handler + "Echoes a GetInput" + [data :- GetInput] + (cqrs/success data)) + + +(s/defschema PostInput + {:data s/Str}) + +(s/defn post-handler + "Echoes a PostInput" + [data :- PostInput] + (cqrs/success data)) (defnk ^:get-post get-and-post "handles both" - {:responses {:default {:schema {:message String}}}} - [data1 data2 #_[:data name :- String] request] + [get-params post-params request] (clojure.pprint/pprint request) (if (= (:request-method request) :get) - (cqrs/success {:message (str "Hello GET, " name)}) - (cqrs/success {:message (str "Hello POST, " name)}))) + (s/with-fn-validation (get-handler get-params)) + (s/with-fn-validation (post-handler post-params)))) (def app (http-api {:core {:handlers {:api [#'get-and-post]} :type-resolver (k/type-resolver :get :get-post :post)} :ring {:types {:get-post {:methods #{:get :post} ; :query-params comes from Ring https://github.com/ring-clojure/ring/wiki/Parameters - :parameters {[:data1] [:request :query-params] - [:data2] [:request :body-params]}}}}})) + :parameters {[:get-params] [:request :query-params] + [:post-params] [:request :body-params]}}}}})) (defonce server (atom nil)) (defn stop-server [] (when-not (nil? @server) - ;; graceful shutdown: wait 100ms for existing requests to be finished - ;; :timeout is optional, when no timeout, stop immediately (@server :timeout 100) (reset! server nil))) (defn -main [&args] - ;; The #' is useful when you want to hot-reload code - ;; You may want to take a look: https://github.com/clojure/tools.namespace - ;; and http://http-kit.org/migration.html#reload (reset! server (server/run-server #'app {:port 3000})) (println "server running in port 3000")) From edb450d44088a9d4662add98cdde1b28824df839 Mon Sep 17 00:00:00 2001 From: Taras Verhun Date: Sat, 11 Jun 2016 01:20:37 +0300 Subject: [PATCH 3/9] added interceptors error handling todo --- examples/get-post/project.clj | 2 +- examples/get-post/src/get_post/core.clj | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/get-post/project.clj b/examples/get-post/project.clj index 2ba670c..812bb44 100644 --- a/examples/get-post/project.clj +++ b/examples/get-post/project.clj @@ -2,4 +2,4 @@ :description "Extended examples" :dependencies [[org.clojure/clojure "1.8.0"] [http-kit "2.1.19"] - [metosin/kekkonen "0.1.0-SNAPSHOT"]]) + [metosin/kekkonen "0.3.0-SNAPSHOT"]]) diff --git a/examples/get-post/src/get_post/core.clj b/examples/get-post/src/get_post/core.clj index df28961..bd6687d 100644 --- a/examples/get-post/src/get_post/core.clj +++ b/examples/get-post/src/get_post/core.clj @@ -15,7 +15,6 @@ [data :- GetInput] (cqrs/success data)) - (s/defschema PostInput {:data s/Str}) @@ -27,17 +26,26 @@ (defnk ^:get-post get-and-post "handles both" [get-params post-params request] - (clojure.pprint/pprint request) + #_(clojure.pprint/pprint request) (if (= (:request-method request) :get) (s/with-fn-validation (get-handler get-params)) (s/with-fn-validation (post-handler post-params)))) +(defn interceptor [ctx] + "logs incoming requests for us" + (let [uri (get-in ctx [:request :uri]) + request-method (name (get-in ctx [:request :request-method]))] + (println (str request-method ": " uri)) + ctx)) + (def app (http-api {:core {:handlers {:api [#'get-and-post]} - :type-resolver (k/type-resolver :get :get-post :post)} + :type-resolver (k/type-resolver :get :get-post :post) + } :ring {:types {:get-post {:methods #{:get :post} ; :query-params comes from Ring https://github.com/ring-clojure/ring/wiki/Parameters :parameters {[:get-params] [:request :query-params] - [:post-params] [:request :body-params]}}}}})) + [:post-params] [:request :body-params]}}} + :interceptors [interceptor]}})) (defonce server (atom nil)) From 4447c1c0614977f48cf6b82145d4fd4557588b46 Mon Sep 17 00:00:00 2001 From: Taras Verhun Date: Sat, 11 Jun 2016 12:13:27 +0300 Subject: [PATCH 4/9] plus error handler --- examples/get-post/src/get_post/core.clj | 32 ++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/examples/get-post/src/get_post/core.clj b/examples/get-post/src/get_post/core.clj index bd6687d..102ed2a 100644 --- a/examples/get-post/src/get_post/core.clj +++ b/examples/get-post/src/get_post/core.clj @@ -1,19 +1,18 @@ (ns get-post.core (:require [org.httpkit.server :as server] [plumbing.core :refer [defnk]] - [kekkonen.http :refer :all] [kekkonen.cqrs :as cqrs] [kekkonen.core :as k] [schema.core :as s])) (s/defschema GetInput - {:name s/Str + {:name s/Str (s/optional-key :description) s/Str}) (s/defn get-handler - "Echoes a GetInput" - [data :- GetInput] - (cqrs/success data)) + "Echoes a GetInput" + [data :- GetInput] + (cqrs/success data)) (s/defschema PostInput {:data s/Str}) @@ -24,9 +23,8 @@ (cqrs/success data)) (defnk ^:get-post get-and-post - "handles both" + "handles both requests" [get-params post-params request] - #_(clojure.pprint/pprint request) (if (= (:request-method request) :get) (s/with-fn-validation (get-handler get-params)) (s/with-fn-validation (post-handler post-params)))) @@ -38,13 +36,19 @@ (println (str request-method ": " uri)) ctx)) -(def app (http-api {:core {:handlers {:api [#'get-and-post]} - :type-resolver (k/type-resolver :get :get-post :post) - } - :ring {:types {:get-post {:methods #{:get :post} - ; :query-params comes from Ring https://github.com/ring-clojure/ring/wiki/Parameters - :parameters {[:get-params] [:request :query-params] - [:post-params] [:request :body-params]}}} +(defn err-handler [ex data req] + "logs exception message and return info to client" + (clojure.pprint/pprint (.getMessage ex)) + (cqrs/failure (.getMessage ex))) + +(def app (http-api {:core {:handlers {:api [#'get-and-post]} + :type-resolver (k/type-resolver :get :get-post :post)} + :mw {:exceptions {#_:default #_err-handler + :handlers {:schema.core/error err-handler}}} + :ring {:types {:get-post {:methods #{:get :post} + ; :query-params comes from Ring https://github.com/ring-clojure/ring/wiki/Parameters + :parameters {[:get-params] [:request :query-params] + [:post-params] [:request :body-params]}}} :interceptors [interceptor]}})) (defonce server (atom nil)) From 79db1e07c5f2ec444cc630aac5b4e02e0ebc4ff6 Mon Sep 17 00:00:00 2001 From: Taras Verhun Date: Sat, 11 Jun 2016 13:52:35 +0300 Subject: [PATCH 5/9] tests added --- examples/get-post/project.clj | 4 +++- examples/get-post/run_tests.bat | 2 ++ examples/get-post/run_tests_auto.bat | 2 ++ examples/get-post/src/get_post/core.clj | 21 ++++++++++--------- examples/get-post/test/get_post/core_test.clj | 14 +++++++++++++ 5 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 examples/get-post/run_tests.bat create mode 100644 examples/get-post/run_tests_auto.bat create mode 100644 examples/get-post/test/get_post/core_test.clj diff --git a/examples/get-post/project.clj b/examples/get-post/project.clj index 812bb44..d9ff1dc 100644 --- a/examples/get-post/project.clj +++ b/examples/get-post/project.clj @@ -2,4 +2,6 @@ :description "Extended examples" :dependencies [[org.clojure/clojure "1.8.0"] [http-kit "2.1.19"] - [metosin/kekkonen "0.3.0-SNAPSHOT"]]) + [metosin/kekkonen "0.3.0-SNAPSHOT"]] + :profiles {:dev {:dependencies [[midje "1.6.3"] + [ring-mock "0.1.5"]]}}) diff --git a/examples/get-post/run_tests.bat b/examples/get-post/run_tests.bat new file mode 100644 index 0000000..16279e8 --- /dev/null +++ b/examples/get-post/run_tests.bat @@ -0,0 +1,2 @@ +set MIDJE_COLORIZE=true +lein midje \ No newline at end of file diff --git a/examples/get-post/run_tests_auto.bat b/examples/get-post/run_tests_auto.bat new file mode 100644 index 0000000..a6b5a3f --- /dev/null +++ b/examples/get-post/run_tests_auto.bat @@ -0,0 +1,2 @@ +set MIDJE_COLORIZE=true +lein midje :autotest \ No newline at end of file diff --git a/examples/get-post/src/get_post/core.clj b/examples/get-post/src/get_post/core.clj index 102ed2a..540647a 100644 --- a/examples/get-post/src/get_post/core.clj +++ b/examples/get-post/src/get_post/core.clj @@ -12,6 +12,7 @@ (s/defn get-handler "Echoes a GetInput" [data :- GetInput] + ; here is your handler (cqrs/success data)) (s/defschema PostInput @@ -20,6 +21,7 @@ (s/defn post-handler "Echoes a PostInput" [data :- PostInput] + ; here is your handler (cqrs/success data)) (defnk ^:get-post get-and-post @@ -38,18 +40,17 @@ (defn err-handler [ex data req] "logs exception message and return info to client" - (clojure.pprint/pprint (.getMessage ex)) + (println (str "ERROR: " (.getMessage ex))) (cqrs/failure (.getMessage ex))) -(def app (http-api {:core {:handlers {:api [#'get-and-post]} - :type-resolver (k/type-resolver :get :get-post :post)} - :mw {:exceptions {#_:default #_err-handler - :handlers {:schema.core/error err-handler}}} - :ring {:types {:get-post {:methods #{:get :post} - ; :query-params comes from Ring https://github.com/ring-clojure/ring/wiki/Parameters - :parameters {[:get-params] [:request :query-params] - [:post-params] [:request :body-params]}}} - :interceptors [interceptor]}})) +(def app (cqrs/cqrs-api {:core {:handlers {:api [#'get-and-post]} + :type-resolver (k/type-resolver :get :get-post :post)} + :mw {:exceptions {:handlers {:schema.core/error err-handler}}} + :ring {:types {:get-post {:methods #{:get :post} + ; :query-params comes from Ring https://github.com/ring-clojure/ring/wiki/Parameters + :parameters {[:get-params] [:request :query-params] + [:post-params] [:request :body-params]}}} + :interceptors [interceptor]}})) (defonce server (atom nil)) diff --git a/examples/get-post/test/get_post/core_test.clj b/examples/get-post/test/get_post/core_test.clj new file mode 100644 index 0000000..9e5bac2 --- /dev/null +++ b/examples/get-post/test/get_post/core_test.clj @@ -0,0 +1,14 @@ +(ns get-post.core-test + (:use midje.sweet) + (:require [clojure.test :refer :all] + [get-post.core :refer :all] + [ring.mock.request :as mock] + [kekkonen.cqrs :as cqrs])) + +(facts "About http handling" + (fact "GET works for get-and-post" + (app (mock/request :get "/api/get-and-post?name=taras")) => cqrs/success?) + (fact "POST works for get-and-post" + (let [r (mock/request :post "/api/get-and-post") + rb (assoc r :body-params {:data "taras"})] + (app rb) => cqrs/success?))) \ No newline at end of file From dcf54c054403a8162eb9ce946307d13b973a87ee Mon Sep 17 00:00:00 2001 From: Taras Verhun Date: Sat, 11 Jun 2016 13:59:44 +0300 Subject: [PATCH 6/9] todos --- examples/get-post/src/get_post/core.clj | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/get-post/src/get_post/core.clj b/examples/get-post/src/get_post/core.clj index 540647a..48a4c91 100644 --- a/examples/get-post/src/get_post/core.clj +++ b/examples/get-post/src/get_post/core.clj @@ -9,6 +9,7 @@ {:name s/Str (s/optional-key :description) s/Str}) +; GET http://localhost:3000/api/get-and-post?name=taras (s/defn get-handler "Echoes a GetInput" [data :- GetInput] @@ -18,6 +19,7 @@ (s/defschema PostInput {:data s/Str}) +; POST http://localhost:3000/api/get-and-post {"data":"taras"} (s/defn post-handler "Echoes a PostInput" [data :- PostInput] @@ -59,9 +61,12 @@ (@server :timeout 100) (reset! server nil))) +;TODO start (defn -main [&args] (reset! server (server/run-server #'app {:port 3000})) - (println "server running in port 3000")) + (println "server running in port 3000") + ;TODO client calls + ) (defn run-server [] (reset! server (server/run-server #'app {:port 3000})) From 72645f6b1b14a122191c1529636329fb638d52f3 Mon Sep 17 00:00:00 2001 From: Taras Verhun Date: Sun, 12 Jun 2016 23:50:19 +0300 Subject: [PATCH 7/9] final --- examples/get-post/README.md | 7 ++++++ examples/get-post/project.clj | 2 ++ examples/get-post/run.bat | 1 + examples/get-post/src/get_post/core.clj | 23 ++++++++++++++----- examples/get-post/test/get_post/core_test.clj | 2 ++ 5 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 examples/get-post/README.md create mode 100644 examples/get-post/run.bat diff --git a/examples/get-post/README.md b/examples/get-post/README.md new file mode 100644 index 0000000..04cba59 --- /dev/null +++ b/examples/get-post/README.md @@ -0,0 +1,7 @@ +# get-post + +A Clojure library designed to show examples of extended usage of Kekkonen. + +## Usage + +Use bat files provided \ No newline at end of file diff --git a/examples/get-post/project.clj b/examples/get-post/project.clj index d9ff1dc..e6588a7 100644 --- a/examples/get-post/project.clj +++ b/examples/get-post/project.clj @@ -2,6 +2,8 @@ :description "Extended examples" :dependencies [[org.clojure/clojure "1.8.0"] [http-kit "2.1.19"] + [clj-http "2.2.0"] [metosin/kekkonen "0.3.0-SNAPSHOT"]] + :main get-post.core :profiles {:dev {:dependencies [[midje "1.6.3"] [ring-mock "0.1.5"]]}}) diff --git a/examples/get-post/run.bat b/examples/get-post/run.bat new file mode 100644 index 0000000..0adfca1 --- /dev/null +++ b/examples/get-post/run.bat @@ -0,0 +1 @@ +lein run \ No newline at end of file diff --git a/examples/get-post/src/get_post/core.clj b/examples/get-post/src/get_post/core.clj index 48a4c91..c909e69 100644 --- a/examples/get-post/src/get_post/core.clj +++ b/examples/get-post/src/get_post/core.clj @@ -1,5 +1,6 @@ (ns get-post.core (:require [org.httpkit.server :as server] + [clj-http.client :as client] [plumbing.core :refer [defnk]] [kekkonen.cqrs :as cqrs] [kekkonen.core :as k] @@ -26,6 +27,11 @@ ; here is your handler (cqrs/success data)) +(defnk ^:query simple-get + "handles get" + [data request] + (cqrs/success data)) + (defnk ^:get-post get-and-post "handles both requests" [get-params post-params request] @@ -38,6 +44,7 @@ (let [uri (get-in ctx [:request :uri]) request-method (name (get-in ctx [:request :request-method]))] (println (str request-method ": " uri)) + #_(clojure.pprint/pprint (:request ctx)) ctx)) (defn err-handler [ex data req] @@ -45,8 +52,9 @@ (println (str "ERROR: " (.getMessage ex))) (cqrs/failure (.getMessage ex))) -(def app (cqrs/cqrs-api {:core {:handlers {:api [#'get-and-post]} - :type-resolver (k/type-resolver :get :get-post :post)} +(def app (cqrs/cqrs-api {:core {:handlers {:api [#'get-and-post + #'simple-get]} + :type-resolver (k/type-resolver :get-post :command :query)} :mw {:exceptions {:handlers {:schema.core/error err-handler}}} :ring {:types {:get-post {:methods #{:get :post} ; :query-params comes from Ring https://github.com/ring-clojure/ring/wiki/Parameters @@ -61,12 +69,15 @@ (@server :timeout 100) (reset! server nil))) -;TODO start -(defn -main [&args] +(defn -main [& args] (reset! server (server/run-server #'app {:port 3000})) (println "server running in port 3000") - ;TODO client calls - ) + (client/get "http://localhost:3000/api/simple-get") + (client/get "http://localhost:3000/api/get-and-post?name=taras") + (client/post "http://localhost:3000/api/get-and-post" {:body "{\"data\":\"taras\"}" + :content-type :json}) + (println "Schema validation demonstration:") + (client/get "http://localhost:3000/api/get-and-post?nameWWW=taras")) (defn run-server [] (reset! server (server/run-server #'app {:port 3000})) diff --git a/examples/get-post/test/get_post/core_test.clj b/examples/get-post/test/get_post/core_test.clj index 9e5bac2..3040dea 100644 --- a/examples/get-post/test/get_post/core_test.clj +++ b/examples/get-post/test/get_post/core_test.clj @@ -6,6 +6,8 @@ [kekkonen.cqrs :as cqrs])) (facts "About http handling" + (fact "GET works for simple-get" + (app (mock/request :get "/api/simple-get?name=taras")) => cqrs/success?) (fact "GET works for get-and-post" (app (mock/request :get "/api/get-and-post?name=taras")) => cqrs/success?) (fact "POST works for get-and-post" From f4324ca8dc1578dbc20f7495ec2100e1c69c1ec7 Mon Sep 17 00:00:00 2001 From: Taras Verhun Date: Sun, 3 Jul 2016 10:08:59 +0300 Subject: [PATCH 8/9] indent 2 --- examples/get-post/src/get_post/core.clj | 38 +++++++++---------- examples/get-post/test/get_post/core_test.clj | 16 ++++---- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/examples/get-post/src/get_post/core.clj b/examples/get-post/src/get_post/core.clj index c909e69..b340956 100644 --- a/examples/get-post/src/get_post/core.clj +++ b/examples/get-post/src/get_post/core.clj @@ -7,37 +7,37 @@ [schema.core :as s])) (s/defschema GetInput - {:name s/Str - (s/optional-key :description) s/Str}) + {:name s/Str + (s/optional-key :description) s/Str}) ; GET http://localhost:3000/api/get-and-post?name=taras (s/defn get-handler - "Echoes a GetInput" - [data :- GetInput] - ; here is your handler - (cqrs/success data)) + "Echoes a GetInput" + [data :- GetInput] + ; here is your handler + (cqrs/success data)) (s/defschema PostInput - {:data s/Str}) + {:data s/Str}) ; POST http://localhost:3000/api/get-and-post {"data":"taras"} (s/defn post-handler - "Echoes a PostInput" - [data :- PostInput] - ; here is your handler - (cqrs/success data)) + "Echoes a PostInput" + [data :- PostInput] + ; here is your handler + (cqrs/success data)) (defnk ^:query simple-get - "handles get" - [data request] - (cqrs/success data)) + "handles get" + [data request] + (cqrs/success data)) (defnk ^:get-post get-and-post - "handles both requests" - [get-params post-params request] - (if (= (:request-method request) :get) - (s/with-fn-validation (get-handler get-params)) - (s/with-fn-validation (post-handler post-params)))) + "handles both requests" + [get-params post-params request] + (if (= (:request-method request) :get) + (s/with-fn-validation (get-handler get-params)) + (s/with-fn-validation (post-handler post-params)))) (defn interceptor [ctx] "logs incoming requests for us" diff --git a/examples/get-post/test/get_post/core_test.clj b/examples/get-post/test/get_post/core_test.clj index 3040dea..a5d4369 100644 --- a/examples/get-post/test/get_post/core_test.clj +++ b/examples/get-post/test/get_post/core_test.clj @@ -6,11 +6,11 @@ [kekkonen.cqrs :as cqrs])) (facts "About http handling" - (fact "GET works for simple-get" - (app (mock/request :get "/api/simple-get?name=taras")) => cqrs/success?) - (fact "GET works for get-and-post" - (app (mock/request :get "/api/get-and-post?name=taras")) => cqrs/success?) - (fact "POST works for get-and-post" - (let [r (mock/request :post "/api/get-and-post") - rb (assoc r :body-params {:data "taras"})] - (app rb) => cqrs/success?))) \ No newline at end of file + (fact "GET works for simple-get" + (app (mock/request :get "/api/simple-get?name=taras")) => cqrs/success?) + (fact "GET works for get-and-post" + (app (mock/request :get "/api/get-and-post?name=taras")) => cqrs/success?) + (fact "POST works for get-and-post" + (let [r (mock/request :post "/api/get-and-post") + rb (assoc r :body-params {:data "taras"})] + (app rb) => cqrs/success?))) \ No newline at end of file From 94a2ff220079a260aad114b38a9d6bb4505c41ca Mon Sep 17 00:00:00 2001 From: Taras Verhun Date: Sun, 3 Jul 2016 10:13:52 +0300 Subject: [PATCH 9/9] comment added --- examples/get-post/src/get_post/core.clj | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/get-post/src/get_post/core.clj b/examples/get-post/src/get_post/core.clj index b340956..bc66992 100644 --- a/examples/get-post/src/get_post/core.clj +++ b/examples/get-post/src/get_post/core.clj @@ -36,6 +36,7 @@ "handles both requests" [get-params post-params request] (if (= (:request-method request) :get) + ; note - with-fn-validation is not thread safe (s/with-fn-validation (get-handler get-params)) (s/with-fn-validation (post-handler post-params))))