pedestal

Louis Kottmann 2020-11-12T12:38:35.128900Z

I have a pedestal app (a REST API) that must respond quickly before actually doing the (long) work i.e: receive a POST request, verify the auth token checks out, data sent is good, then return 200 ok within 3 seconds But after that I actually do some heavy work with lots of branching, and the same branchings can be reused many times, and the pedestal HTTP mechanism is gone because I already replied to the request. I initially thought about turning the branchings into reusable macros, but I realized that's the job pedestal does, except I use it for HTTP requests. And the website says it's not just for HTTP! Great, though how do I get started? what's the entry point to generate a new non-HTTP context, add non-HTTP interceptors, and get it running?

2020-11-12T16:23:16.129200Z

Here's a toy example:

(:require
  [io.pedestal.interceptor :as i]
  [io.pedestal.interceptor.chain :as chain]
  [io.pedestal.interceptor.helpers :as ih])

(def i1 (i/interceptor {:enter (fn [c] (log/info "in i1") c)}))
(def i2 (i/interceptor {:enter (fn [c] (go (log/info "in i2")) c)}))
(def i3 (ih/before (fn [c] (log/info "in i3") c)))
(def my-ints [i1 i2 i3])
(chain/execute {} my-ints)
(chain/execute-only {} :enter my-ints)

Louis Kottmann 2020-11-12T16:24:10.129500Z

that looks great, I'll try it out tonight

Louis Kottmann 2020-11-12T16:24:13.129700Z

thanks!

2020-11-12T16:24:53.129900Z

no prob!