portal

dumrat 2024-02-12T17:45:39.255759Z

Is it possible to attach metadata for a sub-path in the tapped value? I have some http response in the making often of the format:

{:status some-status
 :headers {"Content-Type" "hiccup"}
 :body <some-hiccup-vector>}
I have a wrap-tap-request-response middleware:
(defn- tap-request-response [handler]
  (fn [request]
    (tap> request)
    (let [response (handler request)]
      (tap> response)
      response)))
I can attach metadata to the response and set default viewer to hiccup, but this fails because response is a map. Can I attach it to :body value of the response instead of the entire response? Further, is it possible to auto-expand the response body? I'm pretty sure this isn't supported. Just asking.

👍 1
djblue 2024-02-12T17:49:59.228179Z

If the sub value is a vector, you can update it with the viewer metadata:

(update {:body [:h1 "hi"]}
        :body vary-meta
        assoc :portal.viewer/default :portal.viewer/hiccup)

👍 1
djblue 2024-02-12T17:50:30.004569Z

I'm planning to add support for expanding values based on metadata, just haven't gotten around to it yet.

🚀 2
dumrat 2024-02-12T17:54:29.290849Z

Wow, thanks. Will check out this stuff.

djblue 2024-02-12T18:06:03.568149Z

Actually, for the helper, the following is better:

(update {:body [:h1 "hi"]} :body portal.viewer/hiccup)

djblue 2024-02-12T18:07:33.694039Z

The other way didn't actually work facepalm