Chapter 7. Creating Web Applications with Clojure

Get ready for some fun. This is where it all comes together. We are going to make a web application with Clojure. At the end of this chapter, you will have a working Clojure web app that is not only Clojure on the web server, but also on the frontend with ClojureScript.

Let’s jump in and start. We will begin with getting a web server up and running, which will involve creating a Clojure project with Leiningen, and using a Clojure library called Compojure.

Creating a Web Server with Compojure

Compojure is a Clojure library that provides simple routing for an another lower-level web application library called Ring. One of nice features of Ring is that it allows web applications to be built in modular components. As a result, there is not one particular web app framework that people use in Clojure. Rather, libraries are used, composed, and shared among many applications.

We need a theme. We have been saving one of my favorite encounters in Alice in Wonderland for this example, the time when Alice meets the ever delightful, smiling Cheshire Cat. In honor of him, our project will be named cheshire-cat. At the end of our example, we will have a Clojure server with a ClojureScript frontend that will make a Cheshire Cat fade away.

In our example, we are purposely going to focus on routing, JSON, and simple ClojureScript actions so that you can get a good understanding of the basics. Afterward, we will touch on further areas to explore ...

Get Living Clojure now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.