This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-12
Channels
- # adventofcode (1)
- # announcements (1)
- # atom-editor (4)
- # aws (4)
- # babashka (7)
- # beginners (46)
- # biff (14)
- # calva (11)
- # cljdoc (2)
- # clojure (78)
- # clojure-art (1)
- # clojure-austin (1)
- # clojure-europe (50)
- # clojure-nl (2)
- # clojure-norway (22)
- # clojure-spec (2)
- # clojure-uk (2)
- # clojurescript (72)
- # conjure (6)
- # core-typed (6)
- # eastwood (4)
- # events (1)
- # figwheel-main (11)
- # fulcro (1)
- # guix (1)
- # helix (13)
- # jobs (2)
- # jobs-discuss (4)
- # kaocha (2)
- # malli (5)
- # off-topic (7)
- # pathom (22)
- # pedestal (9)
- # re-frame (29)
- # reagent (7)
- # releases (2)
- # remote-jobs (1)
- # rewrite-clj (12)
- # shadow-cljs (44)
- # sql (13)
- # squint (2)
- # xtdb (17)
Next meetup on Thursday, 9:30 am pacific: https://www.meetup.com/biff-coding/events/288235307/
I think I'll do https://github.com/jacobobryant/biff/issues/132: replace Biff's task
script with bb tasks.
Zoom link: https://us06web.zoom.us/j/83494571827?pwd=Z1p2c2habGJQeldaK09CbkU0UVlzZz09
Hello,
I'm trying to inspect the req
and response
maps in the repl.
I have following handler set-up with an inline def
app.clj
(defn app [req]
(def req)
(ui/page
{}
[:div "Games"]))
router
(def features
{:routes ["/app"
["" {:get app}]]})
after making a request to /app
I evaluated the req
var in the repl instead of the request map it returns:
#object[clojure.lang.Var$Unbound 0x6219bdef "Unbound: #']
How can I go about inspecting both the request and response maps in biff?Thanks Jacob, on a similar note if I want to inspect a xtdb document in the repl in vanilla xtdb I'm aware that this can be achieved by evaluating a query like this:
(def my-node (xt/start-node {}))
(xt/q (xt/db my-node)
'{:find [name id email]
:where....)
;; => #{[data][data]....
How would this be done in biff?the xtdb node is stored at (:biff.xtdb/node @com.biffweb/system)
, so you pass that to xtdb.api/db
and query it in the usual way. there's an example in the repl.clj file that uses a get-sys
helper function.
I used this var to query xtdb:
......
(:require [com.game.repl :as rp]))
(def inspect
(let [{:keys [biff/db] :as sys} (rp/get-sys)]
(biff/q db
'{:find [title]
:where [[_ :game/title title]]})))
It works when implemented on an already running system, but stops the app from compiling between restarts.
Execution error (IllegalArgumentException) at xtdb.api/eval7979$fn$G (api.clj:306).
No implementation of method: :db of protocol: #'xtdb.api/DBProvider found for class: nil
Yeah, I would change that to a function like (defn inspect [] ...)
, so it only runs when you call it yourself from the repl.
(My repl.clj files tend to accumulate lots of functions just like that)
You can also store forms within a (comment ...)
block. If there are functions I call often I sometimes put the invocation in there:
(defn foo []
...)
(comment
(foo)
...)
I've found when querying the request as so:
(defn app [req]
(def req req) ......
req
I get a very detailed map of the 'system', with the request appended at the end.
Class: clojure.lang.PersistentHashMap
Contents:
:biff.xtdb/topology = :standalone
:mailersend/defaults = { [ :from :email.........
org.rocksdb.RocksDB@.....
:reitit.core/match = .....
biff/db = {....
biff.xtdb/node = {.......
I'm interested in querying a limited set of values from the request e.g headers, port, uri, path-params, response, body etc
How can I obtain these values and omit the other information?Yes, it's because the system map gets merged with all incoming requests. If you'd like to see only some keys from the repl you could do e.g. (:headers req)
, or (select-keys req [:headers :port ...])
, or even (apply dissoc req (keys @com.biffweb/system)
.
Thanks for the explanation, super useful. As a bonus I now understand the purpose of those sys
symbols 🎉
heh, yeah... I'm sort of haphazard about calling it req
vs. sys
. I've been wondering if I should just always call it ctx
(short for context) instead