Fork me on GitHub
#ring-swagger
<
2016-02-15
>
jstokes15:02:10

@juhoteperi - update on custom json parsing in compojure-api. got it to work, but had to do some semi-hacky things

jstokes15:02:15

custom middleware looks like this

jstokes15:02:32

(defn custom-json-parse [handler]
  (fn [request]
    (if (= "application/json" (get-in request [:headers "content-type"]))
      (let [new-request (-> request
                            (assoc :body-params (pjson/read-str (slurp (:body request))))
                            (update :headers (fn [headers] (dissoc headers "content-type"))))]
        (handler new-request))
      (handler request))))

jstokes15:02:05

i needed to dissoc the content type or else ring-middleware-format will try to reparse

ikitommi16:02:34

@jstokes how much is the pjson faster than cheshire? We have commit rights to ring-middleware-format, maybe a PR there to make integration simpler?

jstokes16:02:23

In my simple tests it about doubled the throughput - but it was a pretty simple app that spent about 50% of the time doing json (de)serialization.

jstokes16:02:01

Probably a better approach is to switch to something like msgpack but I needed a change without touching the client for now