This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-08
Channels
- # aleph (2)
- # announcements (2)
- # asami (50)
- # babashka (39)
- # beginners (17)
- # calva (61)
- # cider (9)
- # clj-kondo (5)
- # clojure (37)
- # clojure-europe (52)
- # clojure-nl (1)
- # clojure-norway (14)
- # clojure-uk (5)
- # clojurescript (28)
- # cursive (3)
- # datahike (11)
- # datomic (28)
- # deps-new (11)
- # events (3)
- # fulcro (18)
- # google-cloud (1)
- # graphql (8)
- # introduce-yourself (4)
- # jobs (2)
- # leiningen (7)
- # lsp (15)
- # pathom (9)
- # re-frame (6)
- # reagent (35)
- # reitit (17)
- # releases (1)
- # shadow-cljs (20)
- # specter (1)
- # test-check (106)
- # tools-deps (8)
- # uncomplicate (1)
- # vim (29)
Hi all! I have some nested routes like this:
["/:lang"
["/" {... :name :home}]
["/*slugs" {... :name :page}]]
Where *slugs
matches an arbitrarily nested route:
(reitit/match-by-path $router "/en/one/two")
;; {:template "/:lang/*slugs",
;; :data {... :name :page},
;; :result nil,
;; :path-params {:slugs "one/two", :lang "en"},
;; :path "/en/one/two"}
However, it URL-encodes the nested bit when I try to do reverse routing:
(reitit/match-by-name $router :page {:lang :en :slugs "one/two"})
;; {:template "/:lang/*slugs",
;; :data
;; {... :name :page},
;; :result nil,
;; :path-params {:lang "en", :slugs "one/two"},
;; :path "/en/one%2Ftwo"}
Is there a way to disable/control the encoding?https://github.com/metosin/testit#testit-
Hello Good people of Metosin. I think testit had a nice idea. Can I ask why it became Deprecated
status?
Hi, quick question that I’d love some help with. Consider the following code:
(require '[muuntaja.core :as mu])
(require '(clojure.java [io :as io]))
(def new-muuntaja-instance
(mu/create
(-> mu/default-options
(assoc-in
[:formats "application/json" :decoder-opts]
{:bigdecimals true}))))
(->> (io/input-stream (.getBytes "{\"value\":100}"))
(mu/decode new-muuntaja-instance "application/json")
)
(->> (io/input-stream (.getBytes "{\"value\":100.1}"))
(mu/decode new-muuntaja-instance "application/json")
)
I have two simple decode functions that use muuntaja to decode a numeric value. I have configured :bigdecimals
to true
- which decodes doubles as bigdecimals. All well and good, except I would like all values (including ints) to be decoded to bigdecimals for this particular field (as it is 100.1 is a double -> decoded as a bigdecimal, 100 is an int -> decoded as an int).
So you can understand my motivation, I am using a malli schema to validate my json, and this is failing validation for amounts that happen to not have a decimal place in my json (because they are being encoded as ints and I am expecting all values to be bigdecimals). Any idea on how I would ensure consistent bigdecimal encoding for numeric fields using muuntaja?muuntaja uses jsonista under the hood, and one of the things it allows you to do is to provide a :modules
key. You can define your own jacksondatabind module that would give you the behavior you want.
ALso, here is a so answer that may help too (which, although not related to clojure, would give you some insight on what you could try)
Thanks for the tips David, I’ll take a look at creating my own module and see how I get on
does anyone have any examples of applying a middleware (in my case format response as json) for a single route ?
this is what i tried but i get an error
(ring/router [["/foobar"
{:get {:responses {200 {:body map?}}
:handler (constantly (response/ok {:data 123}))}
:middleware [muuntaja/format-negotiate-middleware]}]
,,,])
> HTTP ERROR 500 java.lang.IllegalArgumentException: No implementation of method: :write-body-to-stream of protocol: #'ring.core.protocols/StreamableResponseBody found for class: clojure.lang.PersistentArrayMapThis middleware does not format the response. It is only doing content negotiation. I think you need to include muuntaja/format-response-middleware
. Or consider muuntaja/format-middleware
which gets you negotiation, decoding, and encoding all bundled together.
https://cljdoc.org/d/metosin/reitit-schema/0.5.15/doc/ring/content-negotiation#content-negotiation