Fork me on GitHub
#reitit
<
2018-08-20
>
ikitommi09:08:13

the reitit-http (a.k.a the interceptor module) syntax about to freeze. the ring-handler will take an mandatory options map, which must have an :executor key and can have optionally :interceptors (that are queued for all routes, including the default branch). :executor should satisfy:

(defprotocol Executor
  (queue
    [this interceptors]
    "takes a sequence of interceptors and compiles them to queue for the executor")
  (execute
    [this interceptors request]
    [this interceptors request respond raise]
    "executes the interceptor chain"))

ikitommi09:08:38

here’s a minimal example app with few dummy interceptors:

(ns example.server
  (:require [reitit.http :as http]
            [reitit.ring :as ring]
            [reitit.interceptor.sieppari]
            [ring.adapter.jetty :as jetty]))

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

       ["/hello" {:get (fn [request]
                         {:status 200
                          :body "hello!"})}]])
    (ring/create-default-handler)
    {:executor reitit.interceptor.sieppari/executor
     :interceptors [{:enter identity}]}))

(defn start []
  (jetty/run-jetty #'app {:port 3000, :join? false, :async? true})
  (println "server running in port 3000"))

(comment
  (start))

ikitommi09:08:47

will try to cook up a pedestal sample.

ikitommi09:08:24

it builds on top of reitit-ring, so all handlers (swagger, swagger-ui, default-handler, resource-handler etc) work, only difference is that middleware is replaced with interceptors. The default middleware need to be ported into interceptors at some point.