Fork me on GitHub
#reitit
<
2019-10-02
>
ikitommi09:10:32

Does anyone have examples (from any lang/lib) of good human-readable errors from api endpoints?

danielgrosse13:10:05

One question about the muuntaja lib and especially jsonista. As you use jackson for the json, is it possible to use jackson plugins with jsonista? There is io.openapitools.jackson.dataformat/jackson-dataformat-hal which adds hal notations to classes and I would like to have a middleware which adds the hal output for reitit.

ikitommi18:10:05

@danielgrosse If you mean Jackson modules, sure, Jsonista just wraps Jackson Databind, and ObjectMapper is exposed for configuration. There are samples in jsonista readme how to plug-in modules: https://github.com/metosin/jsonista#examples

ikitommi18:10:42

and you can configure jsonista via muuntaja config. kinda long trail to backtrack, but should be doable.

ikitommi18:10:57

(goal is to add malli schemas to all libs and try to get suggestions, autocomplation etc. “it’s just data” without tooling is kinda horrible dev experience to try to fing all available options, spanning multiple libraries & ns’es)

ikitommi18:10:14

oh, have an example in the current project, which needs joda:

(def muuntaja
  (m/create
    (-> m/default-options

        ;; JSON + Joda
        (assoc-in
          [:formats "application/json" :opts]
          {:mapper (j/object-mapper {:modules [(JodaModule.)]
                                     :date-format "yyyy-MM-dd'T'HH:mm:ss.SSS"
                                     :decode-key-fn true})})
        ;; Transit + Joda
        (update-in
          [:formats "application/transit+json"]
          merge
          {:decoder-opts {:handlers transit-dates/readers}
           :encoder-opts {:handlers transit-dates/writers}}))))

danielgrosse18:10:44

Thanks a lot. I’ll try it out.