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 ... |
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.