Hi fellow Clojurians! I have been writing Clojure professionally for about 8 years now, and recently came across the https://htmx.org library. It provides an elegant way to build dynamic web apps, so I decided to connect it to a clojure backend and the two go together really nicely.
ctmx provides a ‘component’ macro which expands to both an ordinary function and a REST endpoint (via reitit). It feels quite similar to writing clojurescript, except you are fully on the backend with JVM clojure and no compiled js to load on the frontend. The GitHub repo has a demo project which you can start by cloning and typing lein run.
Feedback and suggestions would be much appreciated.
oh this is nice I’ll check it out! I’ve been using clojure+htmx for a while now and it’s such a nice combo. No need to mess around with Cljs to make some SPA-like
I’ll play with it soon and maybe I’ll have some feedback
The idea of combining the element with its own endpoint in one go sounds good already, which was my biggest nuisance.
When you code you feel like you’re on the frontend, but then you think: “oh great I am on full JVM clojure with sync, threads, access to db etc”. It all just fits together, hard to describe you have to experience it yourself.
Oh yeah I get it! I don’t know Javascript so staying in Clojureland was a massive advantage. I was trying Turbo lately, but I think I’ll revert back to Htmx. Turbo is too rooted in RoR and it does not allow the level of flexibility Htmx has.
@Matthew_Molloy on this SPA-like I’m building right now, I have to update multiple divs with a single request. I was using hx-swap-oob before (I’m testing Turbo these days, but I think I prefer Htmx) but I don’t think I had the correct pattern. Do you have an example of that?
htmx checks the top level items. If hx-swap-oob="true" it knows it has to swap in somewhere, so it searches the web page for the matching ID. If none is found it will throw an error.
I was talking to some of the scicloj people (hey @daslu ) that would be cool to have a similar frameework to R’s Shiny for quickly creating simple apps and dashboards to showcase data science projects to non-technical people (a common use case I have).
Shout out if you want any help converting! You might find it easiest to start with the demo project /demo in the ctmx repo. cd in and then just type lein run. You can then copy the /demo directory into a fresh git repo and start making commits.
Hi,
Before today, I don’t know about ctmx, still less about htmx and it’s awesome!
Nice work you done!
I find very useful and interesting these alternative propositions for Clojure ecosystem.
For my part, I had the same feeling when I wrote this Inertia adapter which allow to write back-end the same way but resulting to SPA.
The state, the routing and the logic continues to live on back-end and the front-end libs (Reagent, React, Vue, etc) are used like any templating language.
And icing on the cake, it supports now SSR.
This looks good! Thanks for bringing htmx to attention, I hadn’t come across it before. I was convinced that I wanted to use stimulus.js for my next web project, but htmx looks even better.
I think if I end up finding the time to experiment with this, I will start by building with pure htmx to see the patterns in full, and then convert to ctmx for comparison.
When you decided to build ctmx, was that a result of having used reitit and hiccup to build an htmx app before?
I created ctmx in parallel with my first htmx app. I wanted something that feels like frontend, especially react or clojurescript reagent, but is actually on the backend. I would like suggestions if you have alternative ideas for a clojure/htmx architecture.