mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
sieppari 0.0.0-alpha5
This commit is contained in:
parent
b3a24f2908
commit
13ceab524d
4 changed files with 50 additions and 28 deletions
|
|
@ -10,8 +10,10 @@
|
|||
Go with browser to:
|
||||
|
||||
* http://localhost:3000/api/sync - synchronous
|
||||
* http://localhost:3000/api/async - with core.async
|
||||
* http://localhost:3000/api/future - with futures
|
||||
* http://localhost:3000/api/async - with [core.async](https://github.com/clojure/core.async) channels
|
||||
* http://localhost:3000/api/future - with [futures](https://clojuredocs.org/clojure.core/future)
|
||||
* http://localhost:3000/api/deferred - with [manifold](https://github.com/ztellman/manifold) deferred
|
||||
* http://localhost:3000/api/promesa - with [promesa](http://funcool.github.io/promesa/latest/) promises
|
||||
|
||||
|
||||
## License
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
:description "Reitit Ring App with Swagger"
|
||||
:dependencies [[org.clojure/clojure "1.9.0"]
|
||||
[org.clojure/core.async "0.4.474"]
|
||||
[funcool/promesa "1.9.0"]
|
||||
[manifold "0.1.8"]
|
||||
[ring "1.6.3"]
|
||||
[metosin/reitit "0.2.0-alpha1"]]
|
||||
:repl-options {:init-ns example.server})
|
||||
|
|
|
|||
|
|
@ -1,46 +1,58 @@
|
|||
(ns example.server
|
||||
(:require [reitit.http :as http]
|
||||
[reitit.ring :as ring]
|
||||
[clojure.core.async :as a]
|
||||
[reitit.interceptor.sieppari]
|
||||
[ring.adapter.jetty :as jetty]))
|
||||
[ring.adapter.jetty :as jetty]
|
||||
[clojure.core.async :as a]
|
||||
[manifold.deferred :as d]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(defn -interceptor [f x]
|
||||
(defn interceptor [f x]
|
||||
{:enter (fn [ctx] (f (update-in ctx [:request :via] (fnil conj []) x)))
|
||||
:leave (fn [ctx] (f (update-in ctx [:response :body] str "\n<- " x)))})
|
||||
|
||||
(def interceptor (partial -interceptor identity))
|
||||
(def future-interceptor (partial -interceptor #(future %)))
|
||||
(def async-interceptor (partial -interceptor #(a/go %)))
|
||||
(defn handler [f]
|
||||
(fn [{:keys [via]}]
|
||||
(f {:status 200,
|
||||
:body (str (apply str (map #(str "-> " % "\n") via)) " hello!")})))
|
||||
|
||||
(defn -handler [f {:keys [via]}]
|
||||
(f {:status 200,
|
||||
:body (str (apply str (map #(str "-> " % "\n") via)) " hello!")}))
|
||||
|
||||
(def handler (partial -handler identity))
|
||||
(def future-handler (partial -handler #(future %)))
|
||||
(def async-handler (partial -handler #(a/go %)))
|
||||
(def <sync> identity)
|
||||
(def <future> #(future %))
|
||||
(def <async> #(a/go %))
|
||||
(def <deferred> d/success-deferred)
|
||||
(def <promesa> p/promise)
|
||||
|
||||
(def app
|
||||
(http/ring-handler
|
||||
(http/router
|
||||
["/api"
|
||||
{:interceptors [(interceptor :api)]}
|
||||
{:interceptors [(interceptor <sync> :api)]}
|
||||
|
||||
["/sync"
|
||||
{:interceptors [(interceptor :sync)]
|
||||
:get {:interceptors [(interceptor :hello)]
|
||||
:handler handler}}]
|
||||
{:interceptors [(interceptor <sync> :sync)]
|
||||
:get {:interceptors [(interceptor <sync> :get)]
|
||||
:handler (handler <sync>)}}]
|
||||
|
||||
["/future"
|
||||
{:interceptors [(future-interceptor :future)]
|
||||
:get {:interceptors [(future-interceptor :hello)]
|
||||
:handler future-handler}}]
|
||||
{:interceptors [(interceptor <future> :future)]
|
||||
:get {:interceptors [(interceptor <future> :get)]
|
||||
:handler (handler <future>)}}]
|
||||
|
||||
["/async"
|
||||
{:interceptors [(async-interceptor :async)]
|
||||
:get {:interceptors [(async-interceptor :async-hello)]
|
||||
:handler async-handler}}]])
|
||||
{:interceptors [(interceptor <async> :async)]
|
||||
:get {:interceptors [(interceptor <async> :get)]
|
||||
:handler (handler <async>)}}]
|
||||
|
||||
["/deferred"
|
||||
{:interceptors [(interceptor <deferred> :deferred)]
|
||||
:get {:interceptors [(interceptor <deferred> :get)]
|
||||
:handler (handler <deferred>)}}]
|
||||
|
||||
["/promesa"
|
||||
{:interceptors [(interceptor <promesa> :promesa)]
|
||||
:get {:interceptors [(interceptor <promesa> :get)]
|
||||
:handler (handler <promesa>)}}]])
|
||||
|
||||
(ring/create-default-handler)
|
||||
{:executor reitit.interceptor.sieppari/executor}))
|
||||
|
||||
|
|
|
|||
12
project.clj
12
project.clj
|
|
@ -27,7 +27,7 @@
|
|||
[metosin/ring-swagger-ui "2.2.10"]
|
||||
[metosin/muuntaja "0.6.0-alpha5"]
|
||||
[metosin/jsonista "0.2.1"]
|
||||
[metosin/sieppari "0.0.0-alpha4"]]
|
||||
[metosin/sieppari "0.0.0-alpha5"]]
|
||||
|
||||
:plugins [[jonase/eastwood "0.2.6"]
|
||||
[lein-doo "0.1.10"]
|
||||
|
|
@ -64,7 +64,7 @@
|
|||
[ikitommi/immutant-web "3.0.0-alpha1"]
|
||||
[metosin/muuntaja "0.6.0-alpha5"]
|
||||
[metosin/ring-swagger-ui "2.2.10"]
|
||||
[metosin/sieppari "0.0.0-alpha4"]
|
||||
[metosin/sieppari "0.0.0-alpha5"]
|
||||
[metosin/jsonista "0.2.1"]
|
||||
|
||||
[criterium "0.4.4"]
|
||||
|
|
@ -72,6 +72,10 @@
|
|||
[org.clojure/tools.namespace "0.2.11"]
|
||||
[com.gfredericks/test.chuck "0.2.9"]
|
||||
|
||||
[org.clojure/core.async "0.4.474"]
|
||||
[manifold "0.1.8"]
|
||||
[funcool/promesa "1.9.0"]
|
||||
|
||||
;; https://github.com/bensu/doo/issues/180
|
||||
[fipp "0.6.12"]]}
|
||||
:perf {:jvm-opts ^:replace ["-server"
|
||||
|
|
@ -84,7 +88,9 @@
|
|||
[io.pedestal/pedestal.service "0.5.4"]
|
||||
[io.pedestal/pedestal.jetty "0.5.4"]
|
||||
[org.clojure/core.async "0.4.474"]
|
||||
[metosin/sieppari "0.0.0-alpha4"]
|
||||
[manifold "0.1.8"]
|
||||
[funcool/promesa "1.9.0"]
|
||||
[metosin/sieppari "0.0.0-alpha5"]
|
||||
[yada "1.2.13"]
|
||||
[ring/ring-defaults "0.3.2"]
|
||||
[ataraxy "0.4.0"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue