Fork me on GitHub
#reitit
<
2021-02-11
>
allenj1204:02:24

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)}}))

allenj1204:02:12

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

👌 7
thheller21:02:01

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}"

thheller21:02:25

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

dharrigan21:02:43

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

dharrigan21:02:34

For example...

dharrigan21:02:37

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

dharrigan21:02:52

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

dharrigan21:02:02

will coerce that id to a uuid for me

thheller21:02:25

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

dharrigan21:02:53

always room for one more framework 🙂

thheller21:02:37

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