Fork me on GitHub
#pedestal
<
2020-11-12
>
Louis Kottmann12:11:35

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?

dvingo16:11:16

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 Kottmann16:11:10

that looks great, I'll try it out tonight