reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
ikitommi 2020-04-27T05:45:11.226400Z

@mkvlr fixed the root cause, the path-splitting was done n^2 times, now just n times. For 100 routes, on JVM, it’s 200ms -> 13ms.

1📉22❤️5🦜
ikitommi 2020-04-27T05:55:00.229900Z

@marcus.akre there is no two-way mapping from swagger :consumes and :produces to muuntaja (the content-negotiation library). It only works one-way: setting the values to muuntaja will set the defaults for swagger. If you want to change the content-negotiation default to edn (and strip away support for other formats), you need to change the muuntaja config for the given routes.

Marcus 2020-04-29T08:54:24.261300Z

Now it kind of works. 🙂 In the code below application/json must be kept because if not the swagger ui reports a parsing error. But it means that I still can request json with the accept header.

(def mun
  (m/create
    (m/select-formats
      m/default-options
      ["application/edn", "application/json"])))

Marcus 2020-04-29T08:55:02.261500Z

and to have default edn in swagger ui:

:swagger  {:produces #{"application/edn"}
                        :consumes #{"application/edn"}}

ikitommi 2020-04-27T05:55:13.230Z

here’s the config guide for muuntaja: https://cljdoc.org/d/metosin/muuntaja/0.6.6/doc/configuration

ikitommi 2020-04-27T05:55:58.230300Z

sorry, this could be much simpler, the could be reitit-level :consumes and :produces that both configurate the content-negotiation for the routes and set the swagger info.

ikitommi 2020-04-27T05:56:52.230500Z

OpenApi3 would give better tools for defining these, but not integrated into reitit yet. there is an issue of that, going to reitit 1.0.0

mkvlr 2020-04-27T06:07:55.232100Z

@ikitommi thank you so much! I hope this n^2 performance problem didn’t didn’t give you nightmares

ikitommi 2020-04-27T06:09:49.233600Z

no nightmares 🙂 a fun challenge.

orestis 2020-04-27T06:27:51.233800Z

❤️

Marcus 2020-04-27T06:49:37.233900Z

thank you very much! 🙂 I will look into the muutaja config guide.

mkvlr 2020-04-27T07:01:41.234200Z

🖤

mkvlr 2020-04-27T07:02:42.235Z

can unsurprisingly confirm that the PR makes our router creation a lot faster

oly 2020-04-27T09:07:25.236300Z

hi, is there a way to remove blank query params, will i need a custom middleware for this ?

oly 2020-04-27T09:08:44.237900Z

currently I am replacing a legacy api, and the forntend send query params with out values which my specs barf on, I would like to strip the blanks before spec processes them instead of modifying the specs to accept blanks

oly 2020-04-27T11:19:50.240Z

well I made a middleware, but seems the coercion runs before my middleware, as in if i modify parameters query and disable the coercion I can see they are removed. if I add in the coercion I can see that it errors on a parameter that should have been removed

oly 2020-04-27T11:20:18.240400Z

(defn mw2 [handler]
  (fn [request]
    (handler
     (assoc-in request [:parameters :query]
               (reduce-kv
                (fn [m k v]
                  (if (= "" v) m (assoc m k v)))
                {}
                (-> request :parameters :query))))))
Using this to filter out anything with ""

2020-04-27T19:30:54.244700Z

I want to set up some client-side routing.  Did this once before and it was extraordinarily complicated.  Last time I placed a * route on the backend which returned some empty html, and on the frontend I wrote https://pastebin.com/VVzn9NQT, which is just an intelligent way of hooking into goog.history.Html5History, but extremely brittle and complicated.  Is there a better way to do this now?

2020-04-27T20:49:27.245200Z

It talks about doing a * route but that won't be possible the standard way since I've got a bunch of REST endpoints in the app.