-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.clj
30 lines (27 loc) · 918 Bytes
/
handler.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(ns corbihttp.interceptor.handler
(:require [corbihttp.params :as params]
[exoscale.coax :as c]
[exoscale.ex :as ex]))
(defn assert-spec-valid
[spec params]
(if spec
(ex/assert-spec-valid spec params)
params))
(defn main-handler-enter
[{:keys [request] :as ctx}
{:keys [handler-component]}]
(let [{:keys [handler spec]} (:handler ctx)]
(->> (handler handler-component
(-> request
params/merge-params
(update :all-params
#(->> (c/coerce spec (or % {}))
(assert-spec-valid spec)))))
(assoc ctx :response))))
(defn main-handler
"This interceptor expects that the handler is in the :handler key."
[params]
{:name ::main-handler
:enter (fn [ctx]
(main-handler-enter ctx
params))})