This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-16
Channels
- # beginners (81)
- # calva (6)
- # cider (21)
- # clj-kondo (2)
- # clojure (62)
- # clojure-austin (3)
- # clojure-europe (3)
- # clojure-italy (20)
- # clojure-nl (39)
- # clojure-russia (4)
- # clojure-spec (19)
- # clojure-uk (23)
- # clojurescript (76)
- # cursive (6)
- # data-science (9)
- # datomic (12)
- # defnpodcast (1)
- # figwheel-main (3)
- # fulcro (8)
- # jackdaw (5)
- # jobs (1)
- # jobs-discuss (18)
- # joker (1)
- # leiningen (2)
- # liberator (2)
- # off-topic (148)
- # onyx (5)
- # pedestal (39)
- # planck (7)
- # re-frame (5)
- # reagent (3)
- # reitit (37)
- # shadow-cljs (165)
- # tools-deps (1)
- # yada (19)
Hi, I've set up a route which is complaining that there's no handler for :post
. It's true, there isn't - this resource doesn't accept :post
. What could be causing reitit to be checking this? I have other routes that don't accept :post.
["/sentinel-l1c/:date" {:name "The Sentinel-2 L1C scene for a field on a given date"
:get {:parameters {:path {:date inst?}}
:responses {200 {:body ::l1c/scene}}
:handler get-scene}}]
Execution error (ExceptionInfo) at reitit.middleware/ensure-handler! (middleware.cljc:79).
path "/api/v1/fields/:field-id/sentinel-l1c/:date" doesn't have a :handler defined for :post
oh actually i'm just spotting a 201 response in there, but that's from a higher path in the hierarchy
as there is no :post
in the data. hmm. If you can do a minimal repro and an issue, I could check it out.
ok. this seems to work ok:
(ns user
(:require [reitit.ring :as ring]))
(ring/ring-handler
(ring/router
["/sentinel-l1c/:date"
{:name "The Sentinel-2 L1C scene for a field on a given date"
:get {:parameters {:path {:date inst?}}
:responses {200 {:body {:date inst?}}}
:handler identity}}]))
this reproduces:
(defn app
[]
(ring/ring-handler
(ring/router
["/fruit" {:post {:handle (constantly "post")}}
["/banana" {:get {:handler (constantly "get")}}]])))
(org.httpkit.server/run-server (app) {:port 1234})
why does it identify the nested route that's missing the handler rather than the one that's actually broken?
for nested routes, the paths are concatenated, and the route data merged. sp the :post
gets also merged to the banana-route.
(->
(ring/router
["/fruit" {:post {:handler (constantly "post")}}
["/banana" {:get {:handler (constantly "get")}}]])
(r/routes))
;[["/fruit/banana"
; {:post {:handler #object[clojure.core$constantly]}
; :get {:handler #object[clojure.core$constantly]}}]]
(->
(ring/router
["/fruit"
["" {:post {:handler (constantly "post")}}]
["/banana" {:get {:handler (constantly "get")}}]])
(r/routes))
;[["/fruit"
; {:post {:handler #object[clojure.core$constantly]}}]
; ["/fruit/banana"
; {:get {:handler #object[clojure.core$constantly]}}]]
there is https://github.com/metosin/reitit/issues/175 to make the first one work like it…. should?
with it, it would be:
(->
(ring/router
["/fruit" {:post {:handler (constantly "post")}}
["/banana" {:get {:handler (constantly "get")}}]])
(r/routes))
;[["/fruit"
; {:post {:handler #object[clojure.core$constantly]}}]
; ["/fruit/banana"
; {:post {:handler #object[clojure.core$constantly]}
; :get {:handler #object[clojure.core$constantly]}}]]
ah yes, so i think the trick is to think what my routes would look like flattened - i.e. anything that isn't a leaf in the tree doesn't exist as an independent route. thanks!
Hello, any suggestion how to achieve nested routes in a frontend application with reitit? I am trying to achieve something provided by react-router or vue-router, but since I am at the beginning, I am a bit struggling with it. I checked the example https://github.com/metosin/reitit/blob/master/examples/frontend-controllers/src/frontend/core.cljs but I’d like to render sub-views instead of controlling dom with params/queries. any idea?
and this in react https://reacttraining.com/react-router/web/guides/quick-start/example-nested-routing
The Match
is also available in reitit, but unlike react-router, only one route is matched at a time. Good news is that the data accumulates from root to leaves and this can be done with a new route data key, which has vector or set value.. I think
@juhoteperi most likely knows five good ways to model that ;)
No built-in solution or examples currently. But it is possible to implement this nested route data and vectors, as ikitommi mentioned.
(I'm supposed to mention differences of reitit & js-routers in few days in Clojure/North, so an example of this would be really awesome)
Hah, I'll try to find time to build an example tomorrow. I've already been thinking that the frontend router docs should somehow provide list of things that React-router supports and tell how they can be implemented in Reitit. If we can provide examples for all, or even most, cases, it is a good validation for Reitit.
nice 🙂 that would be really amazing…I have been mostly doing FE apps with React and Vue (using those mentioned routers) and I think it’s great leaving nested-views composition to the router (instead of manually handling it). I’d really appreciate it
Super quick idea without any testing: https://gist.github.com/Deraen/4038244e3cb47d9dcb6b6e59d9e1b96a