This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-02
Channels
- # announcements (13)
- # babashka (42)
- # beginners (29)
- # calva (39)
- # cider (15)
- # clerk (10)
- # clojure (67)
- # clojure-europe (18)
- # clojure-hungary (2)
- # clojure-nl (1)
- # clojure-norway (12)
- # clojure-uk (7)
- # clojuredesign-podcast (14)
- # clojurescript (19)
- # datalevin (1)
- # datascript (5)
- # emacs (4)
- # events (2)
- # fulcro (5)
- # graalvm (5)
- # hyperfiddle (23)
- # incanter (3)
- # jobs (2)
- # lsp (8)
- # missionary (15)
- # off-topic (45)
- # portal (41)
- # practicalli (1)
- # re-frame (3)
- # reitit (6)
- # releases (2)
- # remote-jobs (1)
- # sci (1)
- # shadow-cljs (35)
- # solo-full-stack (8)
- # tools-deps (4)
Hi guys. I’m new to reitit (Tryint to learn it and I’m following the jacekschae’s course) and clojure. I have couple of questions, hope here is the right place to ask them: • What’s middleware and what’s the idea behind it? • What’s the idea behind “coercion is separated from routing”? What’s the other way around and why this is better? • Did I get it correctly: coercion is basically a way to transform something external as data format (json for example) to edn so we can work easly? • What’s that bi-directional routing? • What reitit brings to the table since it’s using ring? I’m coming from the java world and I know apache flink and worked a little bit with spring, but if there’s something similar as a concepts, could you please connect it, so I could understand what’s exactly happening 🙈
I'm just a user but: • if you've used Spring, middleware are Filters • - • https://github.com/metosin/reitit/blob/master/doc/ring/coercion.md • bidirectional routing lets you convert from a path to a route, and the reverse, see https://github.com/metosin/reitit/blob/master/doc/README.md • see https://github.com/metosin/reitit/blob/master/doc/faq.md for comparison with other routing libraries, but also this table on bidi https://github.com/juxt/bidi#comparison-with-other-routing-libraries
“Coercion is separate from routing” means (to me), among other things, that routing is data driven, and you can define your coercion needs also with data, but coercion itself requires the execution of a function to carry out your wishes, so it requires middleware to pull it off.
Bidirectional routing means you can match a path to a route and also match a route to a path. What this means concretely is the following.
(require '[reitit.core :as r])
(def routes
[["/" :index]
["/metrics" :metrics]])
(def router (r/router routes))
(r/match-by-path router "/metrics") ;=> {:template "/metrics", :path "/metrics", :data {:name :metrics}, ...}
(r/match-by-name router :metrics) ;=> {:template "/metrics", :path "/metrics", :data {:name :metrics}, ...}
In the first case, we went from path to route. In the second case, we went from route to path. That is what “bi-directional routing” means.As for what reitit brings to the table: it brings routing and nothing else. Reitit is a routing library, whereas Ring is an abstraction of HTTP requests and responses. The way it works with Ring is as follows: • User requests resource • Ring defines a way to represent HTTP requests and responses as data • In particular, a Ring adapter transforms HTTP requests sent to a web server into a Clojure map • This map contains a URL, and the URL gets passed to Reitit to find a route • Once a route is found, we can use the data of the route to figure out what to do next (e.g. handle the HTTP request) • Your HTTP request handler is a function that returns a response map
@U0479UCF48H thank you very much, really detailed explanation 🙌