Web Apps in Clojure Overview

A typical Web application receives data, does something with it and returns a result. This is the essence of how a function works in Clojure. So its really simple to design web apps with Clojure.

As Clojure is centered around dynamic types and immutable data structures, it makes web applications really easy to build and simple to scale through parallelism. The majority of your application will be stateless, therefore will be 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. Each library has a specific focus and enables a modular approach, as you can swap components & libraries easily should there be value in a different approach.

Common libraries for web app development include:

The closed thing to a framework in Clojure is Pedestal. Frameworks constrain you to a certain approach to building apps and if you can live inside these constraints they can be very powerful.

Project templates

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 common web application approach with ring and compojure
  • compojure-api - quickly build API's with ring, compojure and openapi (swagger) for self-documentation
  • luminus - a flexible template to create server-side and full stack web applications
  • pedestal-service - an opinionated, extensible & scalable framework
  • duct - data-oriented production-grade server-side web applications
  • JUXT Edge - a curated base project to build your own applications and services

You can find a range of project templates by searching for lein-template on Clojars.org. There is also a guide to writing templates on Leiningen.org

results matching ""

    No results matching ""