Blog

Your First Clojure Web App

Experimenting with Clojure has been a fun process. Just to show how easy it is, let's walk through the process of booting your first little web app. This is 100% OS X specific…

Install Clojure

$ brew install clojure It's that easy. Also, use homebrew.

Install Leiningen

Leiningen is a helpful automated project build tool for clojure projects. To install, download the script, make it executable, and place it in your path. It seems to be somewhat analagous to Bundler in the Ruby world.

Full instructions are here: Leiningen Github Page

Start Your Engines

Let's get our project bootstrapped… $ cd ~/dev $ lein new myfirstwebapp $ cd myfirstwebapp/

Dependencies

Open the project.clj file inside of your app directory and add a few dependencies. Now run… $ lein deps …to install the necessary dependencies. You can see that we're depending on Ring, which is an HTTP abstraction library in clojure. It is analagous to Rack.

The Hello World

Let's add a Ring request handler that simply handles all requests with a 200 "Hello World!" html response.

Runtime

To boot your app and have it automatically opened in a browser, run… $ lein ring server Cool, huh?

Conclusion

None of this is to say that Clojure, or other Lisp-y/functional languages, are easy, but that it is FAST to get started with a simple web app. Give it a try.