This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-31
Channels
- # adventofcode (15)
- # announcements (8)
- # babashka (16)
- # beginners (48)
- # braveandtrue (5)
- # calva (54)
- # cider (7)
- # clara (8)
- # clj-kondo (3)
- # cljdoc (3)
- # clojure (37)
- # clojure-europe (1)
- # clojure-italy (15)
- # clojure-losangeles (2)
- # clojure-nl (15)
- # clojure-uk (6)
- # clojurescript (145)
- # community-development (53)
- # cursive (20)
- # data-science (8)
- # datomic (23)
- # duct (2)
- # emacs (22)
- # fulcro (16)
- # gorilla (7)
- # graalvm (7)
- # hoplon (1)
- # malli (7)
- # off-topic (8)
- # rewrite-clj (2)
- # ring (9)
- # spacemacs (2)
- # specter (1)
- # tools-deps (25)
- # vrac (1)
I'm using compojure for an API. All is fine except I can't get access to the original JSON payload from POST requests, which I need for verifying requests. Is this done by changing middlewear?
@slack.jcpsantiago Are you capturing the request
argument to the route? For a GET
macro, they should be in params
and for a POST
they should be in body
(GET "/basic/route/structure" request
(let [params (:params request)]
...))
@ajarosinski Yes, I'm doing that already. What I need is the raw json payload, not the parsed payload as a clojure structure
@slack.jcpsantiago Ah, hmm. That definitely is different than what I responded with, sorry. I don’t know exactly, but I have used the wrap-routes
to add a middleware function and I think that still has the payload as a clojure structure.
What are you trying to accomplish with the raw JSON instead of using the clojure structure?
I need to verify a request from Slack. To do that I need to build a signature from the raw json plus a timestamp they send in the header
@slack.jcpsantiago you need to add a custom middleware that slurps the :body
InputStream, places the slurped (raw) string under some key, e.g. :raw-body
and either a) parses the body itself from JSON into :body-params
, :json-params
(or whatever your application expects) or b) re-creates the InputStream from the parsed body and let’s the normal body-parsing middleware read it.