This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-14
Channels
- # ai (24)
- # announcements (36)
- # babashka (15)
- # babashka-sci-dev (8)
- # beginners (18)
- # biff (4)
- # calva (24)
- # cider (13)
- # clj-kondo (1)
- # clj-on-windows (2)
- # clojars (15)
- # clojure (120)
- # clojure-dev (13)
- # clojure-europe (69)
- # clojure-nl (1)
- # clojure-norway (8)
- # clojure-uk (2)
- # clojurescript (4)
- # core-logic (2)
- # cursive (6)
- # datomic (193)
- # dev-tooling (4)
- # emacs (1)
- # hyperfiddle (57)
- # lsp (56)
- # malli (11)
- # missionary (15)
- # nbb (61)
- # off-topic (8)
- # polylith (8)
- # practicalli (2)
- # proletarian (1)
- # reitit (3)
- # releases (2)
- # remote-jobs (1)
- # shadow-cljs (13)
- # spacemacs (1)
- # specter (2)
- # sql (17)
- # tools-deps (3)
- # vim (38)
Coming from Yada.
When a browser requested some JSON data from an API, it would automatically be converted to HTML with json-html
(https://github.com/yogthos/json-html)
Is there something similar that can be done with Reitit?
It's probably going to be with muuntaja/format-response-middleware
:thinking_face:
I think this is the proper way:
(defn html-encoder [_]
(reify
muuntaja-format/EncodeToBytes
(encode-to-bytes [_ data charset]
(.getBytes
(jh/edn->html data)
^String charset))
muuntaja-format/EncodeToOutputStream
(encode-to-output-stream [_ data charset]
(fn [^OutputStream output-stream]
(.write output-stream (.getBytes
(jh/edn->html data)
^String charset))))))
(def muuntaja-instance
(muuntaja/create
(-> muuntaja/default-options
(update-in [:formats "text/html"]
merge
(muuntaja-format/map->Format {:name "text/html"
:encoder [html-encoder]})))))
But now it's the default choice in swagger 😕