Handlers

Handlers are functions that respond to HTTP requests. They take an request map as an argument, and return a response map.

Handlers are the basic building block of Compojure. They provide a way to define web applications in a purely functional way. Here is a basic handler that outputs "hello world" in response to any request:

(defn hello-world [request]
  {:status  200
   :headers {}
   :body    "Hello World"})

However, in practise, you'd rarely write a handler like this. Handlers are usually built up out of a number of routes defined using the route macro syntax.

Once a handler is written, it can be turned into a Java servlet object using the servlet inline function. It can then be attached to a server:

(run-server {:port 8080}
  "/*" (servlet hello-world))