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….
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
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
adding a Cheshire JSON encoder this way doesn’t help:
(cheshire.generate/add-encoder LocalDate (fn [^LocalDate date ^JsonGenerator gen]
(.writeString gen (.toString date))))
and I can’t find anything in Muuntaja docs about this. Any insight?
@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)
doesn’t work?
okay, this was actually a case of failing to read the exception 😄
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
)
which was included in the error map when the request body didn’t match the spec
ok, cool.