Fork me on GitHub
#reitit
<
2020-05-27
>
ikitommi05:05:48

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

Franklin07:05:50

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

Franklin07:05:15

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

Franklin07:05:10

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

Tanel11:05:25

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.

Tanel11:05:55

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.

ikitommi11:05:56

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

ikitommi11:05:00

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.

Tanel11:05:28

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

ikitommi11:05:52

@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 "/"}

ikitommi11:05:44

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

Taras18:05:13

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