Book Image

Clojure Web Development Essentials

By : Ryan Baldwin
Book Image

Clojure Web Development Essentials

By: Ryan Baldwin

Overview of this book

Table of Contents (19 chapters)
Clojure Web Development Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating the recently added route


Before we can view a page, we have to be able to serve it. We'll be creating a couple of album-related pages in hipstr. So let's create a new hipstr.routes.albums namespace, and also create a route to serve up a page for the /albums/recently-added URL:

  1. Create a new hipstr.routes.albums namespace in the hipstr/routes directory. As with our other route namespaces, we'll be making use of Compojure for creating the route, as well as album-model to retrieve the recently added albums from the database:

    (ns hipstr.routes.albums
      (:require [compojure.core :refer :all]
                [hipstr.layout :as layout]
                [hipstr.models.album-model :as album]))
  2. Next, we'll define a new album-routes defroute that will encapsulate all our albums-related routes for hipstr:

    (defroutes album-routes
      (GET "/albums/recently-added" [] (album/get-recently-added)))
  3. Finally, we have to add the new album-routes to the hipstr app-handler:

    1. Open the hipstr/handler.clj file and add a reference...