Define the Routes with Compojure

Compojure is a routing library built on top of Ring. It provides a way to associate handler functions with a URL and an HTTP method. Let’s add it as a dependency in the ring-app project and see how it works.

 (defproject ring-app ​"0.1.0-SNAPSHOT"
  :description ​"FIXME: write description"
  :url ​"http://example.com/FIXME"
  :license {:name ​"Eclipse Public License"
  :url ​"http://www.eclipse.org/legal/epl-v10.html"​}
  :dependencies [[org.clojure/clojure ​"1.7.0"​]
  [ring ​"1.4.0"​]
  [metosin/ring-http-response ​"0.6.5"​]
  [ring-middleware-format ​"0.7.0"​]
  [compojure ​"1.4.0"​]]
  :main ring-app.core)

With the dependency in place, let’s update the namespace to reference compojure.core ...

Get Web Development with Clojure, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.