In the Wild
A great way to get a feel for working with multiple threads in Clojure is to look at the Compojure library.[30] Compojure helps you route the requests that come into your web application to a suitable response. Here, for example, is a simple placeholder web application for our book store, built with Compojure:
| (ns storefront.handler |
| (:require [compojure.core :refer :all] |
| [compojure.handler :as handler])) |
| |
| (defroutes main-routes |
| (GET "/" [] "Welcome to Blotts Books!!") |
| (GET "/book" [title author] |
| (str "Sorry " title " By " author " is not available."))) |
| |
| (def app (handler/site main-routes)) |
The key bit of code here is the call to defroutes, which allows you to associate a route—/book, for example—with ...
Get Getting Clojure 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.