Fork me on GitHub

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


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


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


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


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.


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.


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


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.


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


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

(def 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 "/"}


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


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"})]