Help required: Translating Compojure routes to Ataraxy

37 views
Skip to first unread message

Shantanu Kumar

unread,
Mar 18, 2018, 12:22:14 AM3/18/18
to Ring
Hi,

I am trying to translate some simple Compojure routes to Ataraxy, but can't get past the latter's routes validator. Can somebody please share pointers?

(defroutes handler-compojure

  (context "/user/:id/profile/:type/" [id type]

    (GET "/" request (h11 id type))

    (PUT "/" request (h12 id type))

    (ANY "/" request (h1x)))

  (context "/user/:id/permissions"    [id]

    (GET "/" request (h21 id))

    (PUT "/" request (h22 id))

    (ANY "/" request (h2x)))

  (context "/company/:cid/dept/:did"  [cid did]

    (PUT "/" request (h30 cid did))

    (ANY "/" request (h3x)))

  (context "/this/is/a/static/route"  []

    (PUT "/" request (h40))

    (ANY "/" request (h4x)))

  (rfn request (hxx)))



Shantanu

James Reeves

unread,
Mar 18, 2018, 9:24:27 AM3/18/18
to Ring
Literally translated, it would look  like:

{["/user/" id "/profile/" type]
 {:get [:h11 id type]
  :put [:h12 id type]
  ""   [:h1x]}

 ["/user/" id "/permissions"]
 {:get [:h21 id]
  :put [:h22 id]
  ""   [:h2x]}

 ["/company/" cid "/dept/" did]
 {:put [:h30 cid did]
  ""   [:h3x]}

 "/this/is/a/static/route"
 {:put [:h40]
  ""   [:h4x]}

 ^{:re #".*"} path [:hxx]}

However, the wildcard routes you have look like they're catching errors. If that's the case, they can more appropriately be handled by the default error results instead. A more idiomatic set of routes would therefore look like:

{["/user/" id "/profile/" type]
 {:get [:h11 id type]
  :put [:h12 id type]}

 ["/user/" id "/permissions"]
 {:get [:h21 id]
  :put [:h22 id]}

 ["/company/" cid "/dept/" did]
 {:put [:h30 cid did]}

 "/this/is/a/static/route"
 {:put [:h40]}}


--
You received this message because you are subscribed to the Google Groups "Ring" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ring-clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
James Reeves
Reply all
Reply to author
Forward
Message has been deleted
0 new messages