This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-11
Channels
- # ai (1)
- # announcements (59)
- # aws (3)
- # babashka (16)
- # beginners (36)
- # calva (29)
- # cider (7)
- # clj-kondo (33)
- # clojure (77)
- # clojure-austin (1)
- # clojure-australia (4)
- # clojure-europe (16)
- # clojure-france (7)
- # clojure-nl (2)
- # clojure-spec (1)
- # clojure-sweden (8)
- # clojure-uk (4)
- # clojurescript (17)
- # cloverage (4)
- # conjure (2)
- # cursive (3)
- # datomic (22)
- # emacs (16)
- # fulcro (10)
- # graphql (3)
- # helix (13)
- # jobs (1)
- # kaocha (1)
- # lsp (7)
- # malli (1)
- # nextjournal (1)
- # off-topic (32)
- # pedestal (8)
- # polylith (5)
- # reitit (4)
- # reveal (1)
- # shadow-cljs (67)
- # spacemacs (7)
- # tools-deps (6)
- # xtdb (4)
How do allow routes to have query params when defined via reitit.ring/ring-handler
?
eg.
(require '[reitit.ring :as rr])
(def handler
(rr/ring-handler (rr/router ["/a" {:get (fn [{:keys [uri]}] {:status 200 :body uri})}]
{})
{}
{}))
(handler {:request-method :get
:uri "/a"})
;;= {:status 200, :body "/a"}
(handler {:request-method :get
:uri "/a?x=10"})
;;= nil
I know the docs mention you can give them via:
(handler {:request-method :get
:uri "/a"
:query-params {"x" 10}})
However, that isn’t useful when the handler is your top-level app dispatched from the server. I’ve tried middleware such as reitit.ring.middleware.parameters/parameters-middleware
, but it still isn’t what I need.
It looks like the :uri
itself needs to have the ?x=10
part removed prior to getting to the router for route matching - since the router is sensitive to anything other than the path.I don’t see any examples of making a server where your routes can optionally have query params (could even be ignored).
Update: I think the answer may be that it is assumed a higher-level middleware/adapter catches it - such as the ring.util.servletring.adapter.jetty/run-jetty
wrapping.
I’m new to reitit and I’ve added a couple routes to https://github.com/metosin/reitit/blob/master/examples/frontend-re-frame/src/cljs/frontend_re_frame/core.cljs but when I go to e.g. http://localhost:8280/authorize by typing it in the URL bar it always takes me to the home page at http://localhost:8280/. But if I dispatch the event the routing works… any idea what I’m missing?