O'Reilly logo

Web Development with Clojure by Dmitri Sotnikov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

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

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

liberator-snippets/home.clj
 
(defroutes home-routes
 
(ANY ​"/"​ request
 
(resource
 
:handle-ok ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required