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
About the Author
About the Reviewers


Clojure is a beautiful, concise language, and its adoption for web applications is ready and about to explode. In Clojure Web Development Essentials, you will learn how to build a Clojure web application from scratch using the Leiningen build tool and the Luminus application template. We'll start by creating a simple example application in the first few pages of the first chapter, and build on that application with each subsequent chapter. We'll cover URL routing, template rendering, database connectivity, form validation, and everything else we need to build a typical web app. By the end of this book, you'll have the knowledge required to venture into the world of web development, and you'll be able to use your skills for the betterment of the Internet.

What this book covers

Chapter 1, Getting Started with Luminus, guides you through creating a new project using the Luminus application template. We'll then dive into what was generated, what the out-of-the-box project dependencies are, and the general file structure of a Luminus web app.

Chapter 2, Ring and the Ring Server, describes the core technologies driving our application, and shows you how to use the development web server.

Chapter 3, Logging, demonstrates configuration of some basic logging and the Clojure logging library, Timbre.

Chapter 4, URL Routing and Template Rendering, starts to dive into the important part of web applications. It shows you how to handle incoming requests using Compojure, and how to render web pages using the Selmer templating engine. We'll also create a sign-up form for our application.

Chapter 5, Handling Form Input, teaches you how to validate form data and report form validation errors back to the user.

Chapter 6, Testing in Clojure, is a quick tour of automated testing and its use in Clojure.

Chapter 7, Getting Started with the Database, is the first of three chapters covering database management and interactivity. We'll set up our application's database, and you will learn how to manage your database schema using the Migratus Leiningen plug. Then we will store the form input created in the fifth chapter using YeSQL.

Chapter 8, Reading Data from the Database, continues exploring database interactivity by teaching you how to retrieve data from the database using YeSQL. We'll then create a couple of new web pages that list the most recently added items in our database.

Chapter 9, Database Transactions, gives us a brief overview of what database transactions are. We'll then create a form that transactionally inserts data into multiple tables.

Chapter 10, Sessions and Cookies, demonstrates how sessions and cookies are managed and maintained in Noir. We'll then create an authentication form for our application, and save a cookie in the user's browser to remember their username the next time they log in.

Chapter 11, Environment Configuration and Deployment, guides us through abstracting our environment configuration (such as database connectivity) and describes a few common ways by which we can deploy our application.

Appendix, Using Korma – a Clojure DSL for SQL, covers the modification of the YeSQL model layers to use Korma, a native Clojure Domain Specific Language that can be used to interact with the database if you're not keen on using raw SQL.

What you need for this book

First and foremost, you must be familiar with the Clojure programming language. You'll also need to install the Leiningen build tool. Familiarity with basic web technology is also valuable.

Who this book is for

This book targets software developers who are already using Clojure but want to use their skill set for web applications. Very little of this book does any fancy frontend development, and most of it focuses on server-side development. If you're primarily a frontend developer, or have never heard of Clojure, this book is precisely not what you are looking for.


In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles and explanations of their meanings.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

  :dependencies [[org.clojure/clojure "1.6.0"]
                [lib-noir "0.9.4"]
                [ring-server "0.3.1"]
                [selmer "0.7.2"]
                [com.taoensso/timbre "3.3.1"]
                [com.taoensso/tower "3.0.2"]

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

:ring {:handler hipstr.handler/app
  :init hipstr.handler/init
  :destroy  hipstr.handler/destroy
  :open-browser? false}

Any command-line input or output is written as follows:

# lein ring server-headless

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book's title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title. Any existing errata can be viewed by selecting your title from


Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.


If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.