Fork me on GitHub
#ring
<
2017-10-03
>
mpenet09:10:13

evaluating routing libs for a project. so much choice now... a lot of good stuff out there

mpenet09:10:15

feel free to suggest good options/experiences

ikitommi14:10:38

@mpenet just cooking up metosin/reitit as was not happy with any of the existing ones. Main features: route syntax for humans, best part of existing libs, supports cljs, middleware & interceptors, pluggable coercion (clojure.spec) & designed perf in mind. First release out soon, would appreciate feedback. https://metosin.github.io/reitit/ & some reasoning https://www.slideshare.net/metosin/performance-and-abstraction#30

mpenet14:10:07

I noticed it, looks interesting but it was too much in alpha state for my needs.

mpenet14:10:15

are you using it already?

mpenet14:10:48

I am leaning towards bidi atm

mpenet14:10:58

I mostly want a simple but extensible data format to describe routing and associated metadata then what it compiles to has little importance for now. I need to port a fairly large legacy app that uses compojure to that format

mpenet14:10:42

@ikitommi first impression, it seems to do too much. Should coercion/middleware'ing be part of a routing lib?

mpenet14:10:25

seems nice otherwise. Another nitpick would be the route params encoded in urls strings is not very friendly to generate stuff from it

mpenet14:10:51

> "/api/orders/:id"

ikitommi16:10:49

@mpenet thanks for the feedback! Idea was to deploy as separate artifacts, one could only depend on the core, which is tiny.

ikitommi16:10:48

not in prod yet, but going there in a ~month.

ikitommi16:10:25

about the path-params... generate stuff from, could you explain a bit?

mpenet16:10:48

"/api/orders/:id" hardcodes the id presence into the url

mpenet16:10:44

it's not really "data" in the sense if I want to document it or its presence I might have to parse the route

ikitommi17:10:50

@mpenet added route-info, which provides the parsed route too:

(def router
  (r/router
    ["/api" {:middleware [::body-params]}
     ["/ping" ::ping]
     ["/admin" {::roles #{:admin}}
      ["/db/:db" {:summary "delete a post"
                  :middleware [::db]
                  :name ::delete-db}]
      ["/ping" ::pong]]]))

(r/routes router)
;[["/api/ping" {:middleware [::body-params]
;               :name ::ping}]
; ["/api/admin/db/:db" {:middleware [::body-params ::db],
;                       ::roles #{:admin},
;                       :summary "delete a post",
;                       :name ::delete-db}]
; ["/api/admin/ping" {:middleware [::body-params]
;                     ::roles #{:admin}, :name ::pong}]]

(mapv r/route-info (r/routes router))
;[{:path "/api/ping",
;  :parts ["api" "ping"],
;  :params #{},
;  :result nil,
;  :meta {:middleware [::body-params]
;         :name ::ping}}
; {:path "/api/admin/db/:fb",
;  :parts ["api" "admin" "db" :db],
;  :params #{:db},
;  :result nil,
;  :meta {:middleware [::body-params ::db],
;         ::roles #{:admin},
;         :summary "delete a post",
;         :name ::delete-db}}
; {:path "/api/admin/ping",
;  :parts ["api" "admin" "ping"],
;  :params #{},
;  :result nil,
;  :meta {:middleware [::body-params]
;         ::roles #{:admin}
;         :name ::pong}}]

mpenet18:10:52

I ll have a look tomorrow, thanks!

mpenet16:10:57

could be a vector instead

mpenet16:10:18

["/api/orders/" :id]

ikitommi16:10:18

There is a parser withing reitit. I’ll paste an example.

ikitommi16:10:51

oh well, it’s not exposed 😮 internally, the routes are parsed into just that form. I’ll add those to r/routes result too.

ikitommi16:10:07

Ataraxy and Bidi both separate parameters and path fragments. It’s a matter of taste.

ikitommi16:10:19

(def routes
  ["/" [["auth/login" :auth/login]
        [["auth/recovery/token/" :token] :auth/recovery]
        ["workspace/" [[[:project-uuid "/" :page-uuid] :workspace/page]]]]])

ikitommi16:10:27

(def routes
  [["/auth/login" :auth/login]
   ["/auth/recovery/token/:token" :auth/recovery]
   ["/workspace/:project-uuid/:page-uuid" :workspace/page]])

ikitommi16:10:19

those were btw from bide, which has a rationale for the syntax too: https://github.com/funcool/bide#why-another-routing-library