reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
allenj12 2021-02-11T04:04:24.086600Z

would something like this be a valid reitit route?

["/id/:entry-id"
       {:get {:handler entry-id
              :parameters {:path {:entry-id int?}}}}
       {:put {:handler replace-entry-at-id
              :parameters {:path {:entry-id int?
                                  :body string?}}}}]
the get request works, but the put 404s the put and get call.
(defn fetch-by-id
  [id]
  (ajax/GET "/entries/id/:entry-id" {:handler #(swap! state entry-handler %1)
                                     :params {:entry-id id}}))

(defn send-update-by-id
  [id]
  (ajax/PUT "/entries/id/:entry-id" {:handler #(println %)
                                     :params {:entry-id id
                                              :body (create-raw)}}))

allenj12 2021-02-11T04:11:12.087Z

ahh I realized :get and :put have to be in the same map, just have a 400 error now

👌 2
thheller 2021-02-11T21:15:01.093700Z

hey everyone. I'd planning to switch some of my routing from my ancient library I wrote myself to reitit. I'm only missing one thing that I kinda got used to and like and wonder if this is something I can easily get done with reitit or if that will get tricky? basically my route syntax matches what reitit already allows "/product/{product-id}" except that it takes an optional "type" conversion via "/product/{product-id:int}"

thheller 2021-02-11T21:16:25.094600Z

actually as I write that I'll probably get :product-id:int "123" in the match data which I could trivially convert later on

dharrigan 2021-02-11T21:17:43.095100Z

For my applications, I'm relying upon malli to do the coercion for me, seems to work out quite well

dharrigan 2021-02-11T21:18:34.095300Z

For example...

dharrigan 2021-02-11T21:18:37.095500Z

(def find-by-id [:map
                 {:closed true}
                 [:id uuid?]])

dharrigan 2021-02-11T21:18:52.095700Z

["/:id" {:get {:handler (find-by-id app-config)
                   :parameters {:path specs/find-by-id}

dharrigan 2021-02-11T21:19:02.096200Z

will coerce that id to a uuid for me

thheller 2021-02-11T21:19:25.096600Z

yeah I know that I can go with the coercion stuff but I like the compact syntax of my stuff 🙂

dharrigan 2021-02-11T21:19:29.096800Z

😄

dharrigan 2021-02-11T21:19:53.097Z

always room for one more framework 🙂

thheller 2021-02-11T21:23:37.097800Z

ok, just tested. I do in fact get :product-id:int "123". that is easy enough to convert. I'll just go with that 🙂

dharrigan 2021-02-11T21:23:56.098Z

:thumbsup: