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 Reitit routes. These resources are defined using the resource and the defresource macros. We need to reference these functions in the liberator-service.handler namespace to start working with Liberator.

 (​ns​ liberator-service.handler
  (:require ...
  [liberator.core :refer [defresource resource]]))

Now we can update our route handler to use a Liberator resource to serve the HTML page:

 (​defn​ loading-page [request]
  (​html5
  (​head​)
  [:body {:class ​"body-container"​}
  mount-target
  (​include-js​ ​"/js/app.js"​)]))
 
 (​def​ app
  (​reitit-ring/ring-handler ...

Get Web Development with Clojure, 3rd Edition 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.