Web Apps in Clojure Overview
A typical Web application receives data, does something with it and return a result. This is the essence of how a function works in Clojure. So again, its really simple to build web apps with.
As Clojure is centered around dynamically typed & immutable data structures, it makes web applications really easy to build and simple to scale through parallelism. As most of your application will be stateless, it is less complex and less prone to conflicts.
Libraries over frameworks
Clojure also takes a very modular approach to building any application and has many great libraries to minimise the work involved. As Java Interoperability is also very easy in Clojure, its trivial to use Java libraries too.
Web apps in Clojure are typically built from a collection of highly focused libraries, that complement each others functions. Talking a modular approach, you can swap components & libraries easily should there be value in a different approach. Common libraries for web app development include:
- Ring - a web application library
- Compojure - an simple way to define routes for your ring webapp
- Hiccup or [Selma]- write html in Clojure
- Korma, YesQL, hugSql - database abstraction layers
- clojure.java.jdbc or clojure.jdbc - low level SQL libraries
- Prismatic Schema - database schema mapping
- Migratus - database migrations (and all the things)
The closed thing to a framework in Clojure is Pedistal. Frameworks constrain you to a certain approach to building apps and if you can live inside these constraints they can be very powerful.
You don't have to build projects from scratch each time, although this is a valid approach. There are many great Clojure project templates available via the build automation tool, Leiningen
Project templates are used as follows
lein new template-name project-name
There are many great templates to try that provide insight into building webapps in Clojure.
- compojure - a simple project with routing
- luminus - a production ready app template
- duct - simple, minimal production-grade framework
- pedestal-service - an opinionated, extensible & scalable framework