A minimal but realistic web service wired together with DI. It runs a Jetty server, routes requests via Reitit, queries an H2 database through HikariCP, and applies Flyway migrations on startup.
The source lives in the repository:
The example is intentionally small but exercises most of the features covered in the tutorial:
di/start / di/stop from user.clj.{::di/stop ...} metadata on
jetty/server (.stop) and hikari/datasource (close-datasource).:component kind — explicit
{::di/kind :component} for reitit/handler and flyway/migrate.root-handler is a regular function that takes
its deps as the first argument.`hikari/datasource) resolve to vars,::handler, ::options) represent abstract
dependencies that the registry binds,"PORT", "H2_URL") are environment variables.di/env-parsing — registers a :env.long parser so that
port :env.long/PORT arrives as a number.di/template — embeds di/ref calls inside data structures
(Reitit route data and Hikari options).di/update-key — extends the shared reitit/route-data from
example.core so each subsystem can append its own routes without
the routing component knowing about them.di/add-side-dependency — pulls in flyway/migrate so
migrations run before the server starts, even though nothing
references the migrator directly.base-registry returns a vector of maps
and middlewares; dev-registry layers dev-only env values on top.From the example/ directory:
clj -M:dev
user=> (start)
;; open http://localhost:8888
user=> (stop)
Redefine example.core/root-handler at the REPL and re-evaluate — the
running system picks up the new implementation without a restart, as
described in the Intro chapter.
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 |