ring-swagger

ring-swagger & compojure-api
abarylko 2017-10-05T02:39:37.000054Z

Is there a middleware to help with controlling rates of calls per endpoint or user? For example users can call only 20 request per second, and customize by endpoint, etc….

arttuka 2017-10-05T07:08:14.000077Z

I’m trying to use compojure-api 2.0.0-alpha7 and I’m having troubles with adding a JSON encoder for a specific class

arttuka 2017-10-05T07:08:58.000017Z

If i return something that contains a java.time.LocalDate, I get this exception:

clojure.lang.ExceptionInfo: Malformed application/json in :muuntaja/encode
Caused by: com.fasterxml.jackson.core.JsonGenerationException: Cannot JSON encode object of class: class java.lang.Class: class java.time.LocalDate

arttuka 2017-10-05T07:09:43.000103Z

adding a Cheshire JSON encoder this way doesn’t help:

(cheshire.generate/add-encoder LocalDate (fn [^LocalDate date ^JsonGenerator gen]
                                           (.writeString gen (.toString date)))) 

arttuka 2017-10-05T07:10:22.000287Z

and I can’t find anything in Muuntaja docs about this. Any insight?

ikitommi 2017-10-05T07:21:53.000127Z

@arttuka Muuntaja uses Cheshire as-is, so should work.

(require '[muuntaja.core :as muuntaja])

;; with defaults
(def m (muuntaja/create))

(cheshire.generate/add-encoder ...)

(->> {:date (t/today)}
     (muuntaja/encode m "application/json")
     slurp)

ikitommi 2017-10-05T07:21:56.000072Z

doesn’t work?

arttuka 2017-10-05T07:52:56.000240Z

okay, this was actually a case of failing to read the exception 😄

arttuka 2017-10-05T07:53:42.000183Z

the error was actually that cheshire didn’t know how to encode java.lang.Class (which happened to be the class object of java.time.LocalDate)

arttuka 2017-10-05T07:54:17.000069Z

which was included in the error map when the request body didn’t match the spec

ikitommi 2017-10-05T08:13:27.000254Z

ok, cool.