A Ring adapter for Inertia.js v3. Ring handlers return page components and props, and a React, Vue or Svelte frontend renders them as a single-page app. You don't need a separate API.
It works with any Ring stack: Reitit, Compojure, http-kit, Jetty, sync or async handlers. Its only dependency is jsonista.
Documentation: https://keanedp.github.io/inertia-clj/ covers responses, prop types, errors and flash, shared props, SSR, testing and protocol coverage, plus the API reference.
;; deps.edn
io.github.keanedp/inertia-clj {:mvn/version "0.1.1"}
;; Leiningen (project.clj)
[io.github.keanedp/inertia-clj "0.1.1"]
(require '[inertia.core :as inertia])
(defn users-index [_req]
(inertia/render "Users/Index"
{:users (fn [] (db/users)) ; lazy: called only if sent
:stats (inertia/defer (fn [] (slow-stats)) "sidebar")
:permissions (inertia/optional (fn [] (perms)))}))
(defn template [{:keys [head body page]} req]
(str "<!DOCTYPE html><html><head>" head (vite-tags) "</head>"
"<body>" body "</body></html>"))
(def app
(-> handler
(inertia/wrap-inertia {:version asset-hash ; string or 0-arity fn
:template template
:share (fn [req] {:auth {:user (current-user req)}})})
wrap-flash
wrap-session))
body contains the <script data-page="app" type="application/json"> element and the <div id="app"> root. Put it in your layout wherever the app should mount. head holds any tags the SSR server returns.
For prop types, SSR, testing helpers and the rest, see the documentation.
examples/react-vite contains a Reitit + Jetty + React 19 app that exercises forms, validation, deferred and optional props, DELETE redirects, external redirects and SSR.
cd examples/react-vite
make vite # terminal 1: Vite on :5173 (runs npm install first if needed)
make server # terminal 2: app on http://localhost:3000
make server SSR=1 # or: with SSR for pages that opt in
Without make:
npm install
npm run dev # terminal 1
clojure -M:run # terminal 2; for SSR set SSR=1 in the environment first
# (PowerShell: $env:SSR = '1')
clojure -M:test # run tests
clojure -T:build jar # build target/inertia-clj-<version>.jar
version in build.clj and in the install snippets of this README and doc/01-getting-started.md. Commit, and tag that commit v<version>.git push origin main v<version>.The release workflow checks that the tag matches build.clj, runs the tests and publishes the jar to Clojars. Clojars never lets a version be overwritten, so a mistake needs a new version. Publishing needs the CLOJARS_USERNAME and CLOJARS_PASSWORD (deploy token) repository secrets. clojure -T:build deploy publishes from your own machine with the same two environment variables.
MIT. See LICENSE.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |