This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-31
Channels
- # announcements (6)
- # babashka (40)
- # beginners (6)
- # calva (1)
- # cider (1)
- # clerk (43)
- # clj-kondo (3)
- # clojure (93)
- # clojure-denver (8)
- # clojure-europe (52)
- # clojure-norway (20)
- # clojure-sweden (7)
- # community-development (5)
- # datascript (15)
- # datomic (30)
- # emacs (24)
- # events (15)
- # fulcro (23)
- # graalvm (12)
- # gratitude (1)
- # helix (4)
- # honeysql (4)
- # hoplon (39)
- # hyperfiddle (7)
- # introduce-yourself (1)
- # jobs (1)
- # jobs-discuss (26)
- # lambdaisland (3)
- # lsp (6)
- # matcher-combinators (2)
- # matrix (5)
- # meander (39)
- # nrepl (4)
- # nyc (1)
- # off-topic (5)
- # portal (73)
- # practicalli (1)
- # re-frame (2)
- # reitit (22)
- # releases (1)
- # remote-jobs (4)
- # shadow-cljs (5)
- # sql (17)
- # testing (1)
- # tools-deps (15)
I was wanting to check the expected params for the reitit-ring/router
function and I see in the relevant https://cljdoc.org/d/metosin/reitit/0.7.0-alpha4/api/reitit.ring#router that it refers to the reitit.core/router for available options, but this namespace doesnt have any generated docs i can see, though the https://github.com/metosin/reitit/blob/master/modules/reitit-core/src/reitit/core.cljc#L313 , are the reitit.core docs unintentionally missing?
ah this is breakage in the 0.7 branch, its ok in the 0.6 one https://cljdoc.org/d/metosin/reitit/0.6.0/api/reitit.core, possibly this cljdoc breakage is the cause https://cljdoc.org/builds/68427 which https://app.circleci.com/pipelines/github/cljdoc/builder/42233/workflows/dc9220f7-a836-4013-a9f2-06600e097b6b/jobs/58608 ctrl/merge.cljc
I have an app packed with most of the reitit features, so everything is wrapped in middleware, including coercion. But I have a handler where I need to access the raw request body for signature verification. Is there a way to either suppress coercion of json only for this endpoint, or better yet, have access to both formats of the body while in the handler?
at least for Jetty, the :body is a read-once inputstream, so once sombody has parsed the body it's no longer available
I've worked around this with an early middleware that does something like (update req :body slurp)
If you're using all the reitit middlewares, including the parameters middleware you'll have the parsed body after format negotiation under body-params. Read it from there, the body key belongs to the server
In the context of coercion, the impetus for the question, I assume raw means unprocessed data structures, not raw bytes as they came in over the wire
@UK0810AQ2 That’s close to what I want… I just want a JSON body in raw text, without JSON coercion so I can use it for calculating the signature. Text is fine, raw bytes are unnecessary.
Okay, that worked perfectly. The last piece of the puzzle is how to include this middleware in the app stack but only enable it for a small set of routes. If I have conditional logic inside the middleware functions, how can I get a simple flag to that middleware?
I don’t completely understand the reitit middleware-as-data completely, but it seems I should be able to have:
:middleware [[wrap-raw-body true]]
Or something like this in the routes where it is needed. But apparently my understanding of the routing is incorrect, because I’m getting stack traces when I hit those routes.
I assume I’m configuring that middleware incorrectly.
You can define middleware per route, like
["/api/healthcheck" ;; affected only by general middleware
{:no-doc true
:get {:summary "Healthcheck for system status"
:parameters {} ; Do not allow any query parameters.
:responses {200 {:body string?}}}
:handler (fn [_]
(if (db/in-sync? db)
{:status 200 :body "ok"}
{:status 503 :body "sync in process"}))}]
["/api"
{:swagger {:tags ["api"]}
:middleware [wrap-request-audit-log ;; special middleware for everything unded /api not affecting other routes
(api-key/create-verification-middleware get-db)
validate-response-with-logging]}
["/some-fn-under-api"
{:put {:summary "Affected by middleware defined in previous level"
:handler
(fn [a]
(put-handler/do-something a))}}]