This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-13
Channels
- # babashka (5)
- # beginners (55)
- # calva (24)
- # cider (11)
- # cljsrn (14)
- # clojure (55)
- # clojure-europe (9)
- # clojure-houston (1)
- # clojure-italy (1)
- # clojure-nl (7)
- # clojure-uk (38)
- # clojurescript (4)
- # code-reviews (12)
- # cursive (3)
- # datomic (86)
- # figwheel-main (14)
- # helix (10)
- # hoplon (4)
- # interceptors (1)
- # jobs (2)
- # jobs-discuss (13)
- # kaocha (5)
- # leiningen (5)
- # local-first-clojure (1)
- # luminus (2)
- # malli (27)
- # membrane (1)
- # off-topic (43)
- # pedestal (5)
- # re-frame (32)
- # reagent (22)
- # reitit (24)
- # remote-jobs (2)
- # shadow-cljs (1)
- # spacemacs (1)
- # sql (1)
- # tools-deps (32)
- # xtdb (51)
this is a bug in core.unify that was fixed years ago (macro emitting fn with a qualified symbol, which violates the spec)
I would guess that using newer deps would pull it in, but I'm not sure what exactly the scope of that is (how much of the dep tree) would need to be updated.
I would expect adding the newest version of org.clojure/core.unify as a dep would probably fix this problem, but I'm not sure if there are other things that should be updated too
newest version is "0.5.7"
and just as a data point on stasis, I have a static site I've been running on stasis for years and still do, but I don't really mess with it much
A common culprit of this is lein ring server. It needs to be 0.12.5 or 0.5.12 (on mobile)
Thanks! Updating Lein Ring Server did the trick, I assume by also updating the org.clojure/core.unify dependency.
when importing a protocol from another namespace and attempting to invoke it in a deftype
, i get clojure.lang.Var cannot be cast to java.lang.Class
how are you using it in the deftype?
should be fine - maybe you have some bad repl state?
noob compojure question:
(defroutes
routes
(POST "/api/" [] emails-handler)
....
(POST "/api/me/checkout/webhook" [] checkout-webhook-handler)
;; static assets
(resources "/" {:root static-root})
(GET "*" [] (render-static-file "index.html")))
...
app (-> routes
wrap-keyword-params
wrap-params
(wrap-json-body {:keywords? true})
wrap-json-response
wrap-cors)
^ Above is a slice of my app with compojure.
problem: Stripe's webhook checkout-webhook-handler
requires the request body to be a string, so I can run sig verification
Buut because I wrap all the routes with wrap-json-body
-- I think this eats the input stream, and I can no longer get the value as a json string.
Is there a simple way I can make
(POST "/api/me/checkout/webhook" [] checkout-webhook-handler)
Out of those wraps?Update: I think the answer is:
(defroutes
api-routes
(context "/api" []
(POST "/emails" [] emails-handler)
...))
(defroutes
webhook-routes
(POST "/webhooks/stripe" [] webhooks-stripe-handler))
(defroutes
static-routes
(resources "/" {:root static-root})
(GET "*" [] (render-static-file "index.html")))
...
app (routes
(-> api-routes
wrap-keyword-params
wrap-params
(wrap-json-body {:keywords? true})
wrap-json-response
wrap-cors)
webhook-routes
static-routes)
Buut for some reason I am not able to trigger the webhook handler.Update: The reason this didn't work, is because my
wrap-cors
middleware (custom written), would always add into response headers. This would tell ring to "stop" checking other routes, as it did get a response back
I thought the json middleware only turned it into json when the content type was application/json
indeed -- unfortunately though -- stripe's webhook request does say application/json xD
What's the best way to evaluate available libraries? For example, I'm trying to decide on a Markdown parser, by looking through https://clojars.org — is this the best way to see what's popular, updated, etc? Is there a better place to look?
I always just search duckduckgo for "clojure <thing>"
usually that will turn up results on github which I think generally has more relevant information for deciding which library might be the best fit
I was thinking this the other day it'd be nice if Clojars had a popular section or trending section etc
@micah688 https://www.clojure-toolbox.com/ can be a good place to look for libraries that solve specific problems. It's not exhaustive and it's not always completely up-to-date but it can give you a sense of where the ecosystem is for a particular task.
for new projects, tools.deps, lein or something else?
@bitpadawan I would recommend the Clojure CLI / deps.edn
at this point for new projects. Create the new project with clj-new
(`clj -A:new ...` if you are using the aliases from my dot-clojure repo) so that it has a full pom.xml
and some useful basic aliases in deps.edn
.
Hi, what is the idiomatic way to dynamically create the vector passed to select-keys? I have a fixed set of keys that I want to always select and a single key that only some of the time.
it can be any collection (eg. set, vector, list) - you can use the standard collection ops to add or remove elements
artificial example
user=> (select-keys {:a 0 :b 1 :c 2} (conj #{:a} :c))
{:c 2, :a 0}
Sounds like (cond-> [:fixed :set :of :keys] (some-time) (conj :single-key))
?
(set or vector)
yeah, I suggest set for doing this dynamically, since sets have the semantics we like (you can remove items by equality, you don't care about order, having an item twice has no meaning)
nil is just another value
sorry, misread
you can just do an unconditional (disj s nil)
after merging in the keys
good advice on set, I am using cljs and still operating with js mindset, so I overuse vectors 😞
It’s not a joke? Lodash lets you apply functions that transform all collections rather than just arrays
So what kind of collections do you use in javascript? 🙂 I like to use Object literals, but if I need to take an object and manipulate it, I always do an .entries first and then a fromEntries when I finished, or something analogues. Do you use Set a lot with lodash?
hi folks, which libraries, books and/or tutorials do you recommend for writing a web (rest) api?
You may find this article which I wrote almost two years ago. https://www.demystifyfp.com/clojure/blog/restful-crud-apis-using-compojure-api-and-toucan-part-1/ If I am starting today, I’d be replacing the following
Componjure-api with Reitit Prismatic Schema with core.spec toucan with HoneyEQL I am planning to write about this in near feature