Defining Resources

Liberator uses the concept of resources to interact with the client. The resources are simply Ring-compliant handlers that can be used inside your Compojure routes. These resources are defined using the resource and defresource macros. Let’s open the liberator-service.routes.home namespace. We’ll remove the reference to layout and add the references for resource and defresource to the declaration:

(​ns​ liberator-service.routes.home
(:require [compojure.core :refer :all]
:refer [defresource resource request-method-in]]))

Now we can replace our "/" route with a resource as follows:

(defroutes home-routes
(ANY ​"/"​ request
:handle-ok ...

Get Web Development with Clojure now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.