This episode is for subscribers only. Sign Up or Log in to watch it.

21. Compojure

Published 09 December 16

Compojure is one of the more popular routing libraries for Ring. It’s easy to pick up, and gives you a great foundation to further explore Clojure web development.

Show notes

Compojure is a routing library for Ring. It is particularly known for its minimalism, making it suitable for smaller apps and APIs. It’s also a great starting point for further exploring Clojure web development.

At the heart of any Clojure web stack you’ll find Ring. The Ring specification defines key abstractions for representing HTTP requests and responses using maps, providing a uniform interface to program to.

A Ring adapter is all you need to get started. It forms the bridge between a HTTP server and your own Ring handler, which is a function that handles requests.

Implementing Ring handlers from scratch is a great learning exercise, but in a real world app you don’t want to reinvent the wheel. Every app will need some kind of dispatching based on the requests URI path and HTTP method, like GET, PUT, or POST. This is the job of a routing library, such as Compojure.

I’m starting a new blank project to build upon in this and coming episodes.

lein new compobook

Most leiningen templates don’t yet initialize Git, so it’s got to do that manually before making any changes. This way it’s easy to see later on which parts are provided by the template, and which were added by you.

browse source code

This episode is a sequel to the series on Ring (part 1, part-2, and part 3). You should be familiar with Ring request and response maps, handlers, adapters, and middleware.

Covered in this episode

Compojure:

ring.util.response: