currently i am playing with Yada as web lib. Now i want to execute some function before a route is hit.
Approaches I have tested: - wrap the current resource as sub-resource, but then the swagger-doc doesn't find the resource - using an prepend-interceptor, but the docu is not complete at this point at i got errors
My code:
(ns all-mighty.namespace
(:require [yada.yada :refer [handler listener resource as-resource]]
[yada.swagger :refer [swaggered]])
(defn resources []
[""
(swaggered
[""
[
(cool-route)
]]
{:info {:title "Hello You!"
:version "1.0"
:description "It's something"}
:basePath ""}
)])
(defn cool-route []
["/cool" (resource {
:description "Returns somethign cool"
:produces "application/json"
:methods {:get {:response cool-response}}}
)])
(defn cool-response [ctx]
(-> (:response ctx)
(assoc :status 200)
(assoc :body {:state :up}))
Yeah, I'll refactor the resources latter ;-)
Does someone has an idea?
The way I'm using
append-interceptor
:So for every resource under
/cool
you can use themy-cool-resource
function to automatically add the desired interceptor.