reitit/doc/http/sieppari.md
Joel Kaasinen 373ea9bb62
Some checks are pending
testsuite / Clojure 11 (Java 11) (push) Waiting to run
testsuite / Clojure 11 (Java 17) (push) Waiting to run
testsuite / Clojure 11 (Java 21) (push) Waiting to run
testsuite / Clojure 11 (Java 25) (push) Waiting to run
testsuite / Clojure 12 (Java 11) (push) Waiting to run
testsuite / Clojure 12 (Java 17) (push) Waiting to run
testsuite / Clojure 12 (Java 21) (push) Waiting to run
testsuite / Clojure 12 (Java 25) (push) Waiting to run
testsuite / ClojureScript (push) Waiting to run
testsuite / Lint cljdoc.edn (push) Waiting to run
testsuite / Check cljdoc analysis (push) Waiting to run
Release 0.10.0
2026-01-09 10:07:15 +02:00

2 KiB

Sieppari

[metosin/reitit-sieppari "0.10.0"]

Sieppari is a new and fast interceptor implementation for Clojure, with pluggable async supporting core.async, Manifold and Promesa.

To use Sieppari with reitit-http, we need to attach a reitit.interceptor.sieppari/executor to a http-router to compile and execute the interceptor chains. Reitit and Sieppari share the same interceptor model, so all reitit default interceptors work seamlessly together.

We can use both synchronous ring and async-ring with Sieppari.

Synchronous Ring

(require '[reitit.http :as http])
(require '[reitit.interceptor.sieppari :as sieppari])

(defn i [x]
  {:enter (fn [ctx] (println "enter " x) ctx)
   :leave (fn [ctx] (println "leave " x) ctx)})

(defn handler [_]
  (future {:status 200, :body "pong"}))

(def app
  (http/ring-handler
    (http/router
      ["/api"
       {:interceptors [(i :api)]}

       ["/ping"
        {:interceptors [(i :ping)]
         :get {:interceptors [(i :get)]
               :handler handler}}]])
    {:executor sieppari/executor}))

(app {:request-method :get, :uri "/api/ping"})
;enter  :api
;enter  :ping
;enter  :get
;leave  :get
;leave  :ping
;leave  :api
;=> {:status 200, :body "pong"}

Async-ring

(let [respond (promise)]
  (app {:request-method :get, :uri "/api/ping"} respond nil)
  (deref respond 1000 ::timeout))
;enter  :api
;enter  :ping
;enter  :get
;leave  :get
;leave  :ping
;leave  :api
;=> {:status 200, :body "pong"}

Examples

Simple

With batteries