January 2018
Intermediate to advanced
336 pages
7h 56m
English
A Pedestal interceptor can be defined as a map with the keys :name, :enter, :leave, and :error. For example, an interceptor msg-play can be defined for the /hello route of the pedestal-play project to change the query parameter name to upper case at the time of entry using the :enter function and appending a greeting at the time of exit using the :leave function. It is followed by the handler hello-page that reads the query parameters and adds a Hello greeting. Take a look at the following example:
;; Handler for /hello route(defn hello-page [request] (ring-resp/response (let [resp (clojure.string/trim (get-in request [:query-params :name]))] (if (empty? resp) "Hello World!" (str "Hello " resp "!")))))(def msg-play
Read now
Unlock full access