Fork me on GitHub
#reitit
<
2019-01-23
>
Vincent Cantin07:01:56

I have this error when trying to use muunjata in reitit, did I forget to add a dependency? which one could it be?

Syntax error (NoSuchMethodError) compiling at (reitit.clj:50:1).
com.fasterxml.jackson.core.JsonGenerator.writeStartObject(Ljava/lang/Object;)V

Vincent Cantin07:01:48

Nevermind, it worked by adding [metosin/muuntaja-cheshire "0.6.3"]

ikitommi08:01:33

@vincent.cantin good that it got solved. The root cause is that Muuntaja uses Jsonista, which leans on quite recent versions of Jackson. Most of the Clojure libraries still use old version of Cheshire, and Maven pulls the older version. Depending directly on latest Jackson solved this, e.g. [com.fasterxml.jackson.core/jackson-databind "2.9.7"]+.

ikitommi08:01:58

If there is a way to force Maven to use the new enough version, let me know.

ikitommi08:01:36

Cheshire itself got a update, but we should update all the libs using cheshire…..

Vincent Cantin16:01:36

@ikitommi I don’t see how to use reitit coercion to fully replace wrap-keyword-params: with the coercion, the programmer needs to specify a :parameters map entry while I am under the impression that with wrap-keyword-params the conversion is made for all parameters.

Vincent Cantin16:01:58

Maybe adding reitit.ring.middleware.parameters/keyword-parameters-middleware would be useful.

(require '[ring.middleware.keyword-params :as keyword-params])

(def keyword-parameters-middleware
  {:name ::keyword-parameters
   :wrap keyword-params/wrap-keyword-params})

ikitommi17:01:16

@vincent.cantin doesn’t the wrap-keyword-params only do it for :params?

ikitommi17:01:42

Do you have a use case for those? We are defining the parameters explicitly per type (`:query`; :path etc)

ikitommi17:01:36

I’m not even sure what middleware/interceptor populates the :params anymore…

kanwei18:01:06

how do you use nested routers (https://metosin.github.io/reitit/advanced/composing_routers.html) with reitit-ring? using the examples, I get

#error{:cause "path \"/api/v4/*\" doesn't have a :handler defined"

kanwei18:01:25

what I'm really just trying to do is to reuse routes for versioned API endpoints that have mostly the same routes, eg /api/v1/blah shares the same code as /api/v2/blah

ikitommi18:01:20

Best way to reuse routes is to define them as values and put the values into multiple places in the routing tree

ikitommi18:01:53

E.g.

[["/v1" common-routes v1-routes]
 ["/v2" common-routes v2-routes]]

ikitommi18:01:17

routes are just data so easy to copy&paste

ikitommi19:01:43

nesting routers doesn't seem to have a ring example, I would guess you would need to put a reitit.ring/ring-handler as a :handler of the parent catch-all route.