reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
ikitommi 2020-05-27T05:39:48.002300Z

[metosin/reitit "0.5.2"] is out with improvements to default swagger mappings & malli, ring & http coercion.

dharrigan 2020-05-27T05:40:14.002800Z

:thumbsup:

Franklin 2020-05-27T07:38:50.003200Z

Hey all, is there a way to have two routes in one router that look like the following without having conflicts

Franklin 2020-05-27T07:39:15.003600Z

["/" [":name" {:name :organization}] [""  {:name :home}]]

Franklin 2020-05-27T07:41:10.005100Z

such that a route like "/test" would match organization and "/" would match home

Tanel 2020-05-27T11:07:25.007400Z

All of my routes deal with JSON, but one of the routes is used for submitting text/xml data in the body via POST. What's the best way to annotate that? I'm still reading the docs but I don't yet understand everything.

ikitommi 2020-05-28T09:55:57.013300Z

https://github.com/metosin/muuntaja/pull/114

Tanel 2020-05-27T11:27:55.008100Z

I'm using the Swagger plugin so it would be nice for it to say "Hey, this endpoint only accepts an XML body" Also, the XML body is to be converted into JSON upon receiving. I'm reading through the middleware and coercion documentations, but not sure yet how to do that.

ikitommi 2020-05-27T11:30:52.009100Z

@franklineapiyo hi. I think it should work out-of-the-box:

(def router
  (r/router
    [["/:name" :organization]
     ["/" :home]]))

(r/match-by-path router "/test")
;#reitit.core.Match{:template "/:name",
;                   :data {:name :organization},
;                   :result nil,
;                   :path-params {:name "test"},
;                   :path "/test"}

(r/match-by-path router "/")
;#reitit.core.Match{:template "/"
;                   :data {:name :home}
;                   :result nil
;                   :path-params {}
;                   :path "/"}

ikitommi 2020-05-27T11:31:56.009200Z

just to annotate the endpoint, add {:swagger {:consumes ["application/xml"]}}to route-data

ikitommi 2020-05-27T11:33:00.009400Z

for parsing xml, there is a PR for adding it to muuntaja. Before that, you should read the body yourself, e.g. (-> request :body slurp parse-xml). There are many xml-libs for Clojure, I belive.

ikitommi 2020-05-27T11:36:44.010400Z

path parameters can’t be empty, so they don’t conflict.

Tanel 2020-05-27T11:53:28.010500Z

Which PR is it? Would be interesting to check it out. Thanks for the quick feedback!

Taras 2020-05-27T18:19:13.013Z

Hey all, can you please suggest how can I forward all my route to index.html for SPA routing? Using compojure I made it like this

(GET "/api" [] api-handler)
(resources "/")
(GET "/**" [] (resource-response "index.html" {:root "public"}))
With reitit I am trying following, but it doesn't work
["/**" (ring/create-resource-handler {:path "index.html"})]