Fork me on GitHub
#reitit
<
2020-04-27
>
ikitommi05:04:11

@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.

parrot 20
❤️ 8
gotta_go_fast 8
📉 4
ikitommi05:04:00

@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.

ikitommi05:04:58

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.

ikitommi05:04:52

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

Marcus06:04:37

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

Marcus08:04:24

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

Marcus08:04:02

and to have default edn in swagger ui:

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

mkvlr06:04:55

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

ikitommi06:04:49

no nightmares 🙂 a fun challenge.

mkvlr07:04:42

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

oly09:04:25

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

oly09:04:44

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

oly11:04:50

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

oly11:04:18

(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 ""

doubleagent19:04:54

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?

doubleagent20:04:27

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.