Fork me on GitHub
#ring-swagger
<
2017-10-05
>
abarylko02:10:37

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

arttuka07:10:14

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

arttuka07:10:58

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

arttuka07:10:43

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

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

arttuka07:10:22

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

ikitommi07:10:53

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

ikitommi07:10:56

doesn’t work?

arttuka07:10:56

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

arttuka07:10:42

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)

arttuka07:10:17

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