This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-01
Channels
- # announcements (2)
- # babashka (26)
- # beginners (26)
- # biff (18)
- # boulder-clojurians (2)
- # cider (16)
- # clj-kondo (34)
- # cljs-dev (4)
- # clojure (22)
- # clojure-denver (10)
- # clojure-europe (16)
- # clojure-nl (1)
- # clojure-norway (10)
- # clojure-uk (2)
- # clojurescript (25)
- # conjure (3)
- # cursive (11)
- # datomic (11)
- # dev-tooling (6)
- # emacs (6)
- # etaoin (7)
- # events (1)
- # fulcro (6)
- # humbleui (11)
- # hyperfiddle (15)
- # instaparse (2)
- # introduce-yourself (2)
- # jobs-discuss (1)
- # lsp (26)
- # malli (7)
- # reitit (5)
- # releases (1)
- # sci (6)
- # shadow-cljs (16)
- # specter (5)
- # vim (5)
What are people using to handle form data with http-kit
and babashka? Just ring middleware?
Ring by itself doesn’t work. I can do JSON, but considering ring doesn’t work, there are a bunch of other things like cookies and so on. Maybe it is time to move this to Clojure
Here’s my bb.edn(simplified)
{:paths ["src"]
:deps {ring/ring-defaults {:mvn/version "0.3.4"}}}
And with this
user=> (require '[ring.middleware.defaults])
clojure.lang.ExceptionInfo: Unable to resolve classname: java.net.JarURLConnection [at ring/util/response.clj:278:20]
(ns bbform)
(require '[org.httpkit.server :as srv])
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {ring/ring {:mvn/version "1.10.0"}}})
(require '[ring.middleware.params :as params])
(defn show-params-handler [req]
{:body (pr-str (:form-params req))})
(def handler (params/wrap-params show-params-handler))
(srv/run-server handler {:port 1234})
(println "Running server on ")
@(promise)
curl -d foo=bar
{"foo" "bar"}%
with cookies:
(ns bbform)
(require '[org.httpkit.server :as srv])
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {ring/ring {:mvn/version "1.10.0"}}})
(require '[ring.middleware.params :as params])
(require '[ring.middleware.cookies :as cookies])
(defn show-params-handler [req]
{:body (pr-str (:form-params req))})
(def handler (-> show-params-handler
params/wrap-params
cookies/wrap-cookies))
(srv/run-server handler {:port 1234})
(println "Running server on ")
@(promise)
As shown above, it's probably best to test individual middlewares. If a specific one doesn't work, welcome to post issues, they are likely fixable (either in bb or in ring)
Babashka news of April 2023: https://github.com/babashka/babashka/blob/master/doc/news.md#2023-04-twitter-mastodon
Something new every month! Colocated bb.edn is a small change but reduces friction significantly
For those who miss set -x
when writing Babashka scripts, I created a library to wrap babashka.process
functions with a default :pre-start-fn
:
https://github.com/rads/xtrace
Note that the official syntax for process
is now also (process opts+args)
so the opts map goes first, it was "unified" with shell
a while ago
Note that you can get the behavior of your library as well when you do:
(alter-var-root #'process/*defaults* assoc :pre-start-fn ...)
But this dynamic var wasn't properly working until a few commits ago on master inside of bbI do miss set -x – thanks for starting this thread and library
@U04V15CAJ: I would like to encourage others to use *defaults*
as well. (I made the library before I knew about *defaults*
.)
I suppose the only thing blocking me would be compatibility with older versions of bb
. Would it be enough to bump babashka.process
to use *defaults*
or is upgrading to latest bb
a requirement?
well. bb process is built-in to bb so either upgrade bb (but first it has to be released, the commit is still only on master) or require process with :reload
. :reload
will work in older versions