Clojure Web Development Essentials
eBook - ePub

Clojure Web Development Essentials

Ryan Baldwin

Share book
  1. 232 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Clojure Web Development Essentials

Ryan Baldwin

Book details
Book preview
Table of contents
Citations

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Clojure Web Development Essentials an online PDF/ePUB?
Yes, you can access Clojure Web Development Essentials by Ryan Baldwin in PDF and/or ePUB format, as well as other popular books in Informatique & Programmation Open Source. We have over one million books available in our catalogue for you to explore.

Information

Year
2015
ISBN
9781784392222

Clojure Web Development Essentials


Table of Contents

Clojure Web Development Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Getting Started with Luminus
Leiningen
Using Leiningen
Generating the application
Getting help
Dependencies of the app
Luminus file structure
util.clj
session_manager.clj
layout.clj
middleware.clj
routes/home.clj
handler.clj
repl.clj
Summary
2. Ring and the Ring Server
Understanding Ring in Clojure
Request maps
Response maps
Handlers
Middleware
Adapters
What is the Ring Server?
hipstr.handler
Initialization hooks
Shutdown hooks
App routes
The application handler
hipstr.repl
Start-server
Stop-server
Get-handler
Configuring and running the Ring Server
Summary
3. Logging
What is Timbre?
What is an appender?
Configuring a Timbre appender
Timbre log levels
Appender configuration keys
Appender map
Shared appender configuration
Logging with Timbre
Adding an appender
Adding the rolling appender
Summary
4. URL Routing and Template Rendering
What is Compojure?
Creating a Compojure route
Using defroutes
Anatomy of a route
Defining the method
Defining the URL
Parameter destructuring
Destructuring the request
Destructuring unbound parameters
Constructing the response
Generating complex responses
What is Selmer?
Creating your first page
Rendering a page
Variables
Filters
Filter parameters
Tags
Template inheritance
Editing the home page
Serving the signup form
Creating the signup page
Summary
5. Handling Form Input
Handling the form POST
Validating the form POST
The noir.validation namespace
The Validateur library
Adding the Validateur dependency
Creating the user validation namespace
Validating required fields
Validating the format
Validating length of values
Validation predicates
Making reusable validators
Reporting errors to the user
Summary
6. Testing in Clojure
The necessity of testing
Anatomy of a test
Writing and running our first test
Running tests
Running tests automatically
Refactoring tests
Writing a high-level integration test
Using ring.mock.request
Summary
7. Getting Started with the Database
Creating the database schema
Maintaining the database schema
Migratus
Getting Migratus
Configuring Migratus
Creating the user table
Dropping the user table
Running the down scripts
Migrating the database
Running all migration scripts from Leiningen
Running migrations programatically
Adding migrations to the hipstr initialization
Adding data to the database
What is YeSQL?
Getting YeSQL
Adding a user to the database
Inserting a user using SQL
Inserting a user using Clojure
Bringing it all together
Adjusting the route
Encrypting the password
Summary
8. Reading Data from the Database
Creating the catalog
Creating the artists table
Seeding the artists table
Creating the albums table
Fetching albums from the database
Writing the SQL query
Creating the albums model
Refactoring the connection
Creating the recently added route
Rendering the results
An exercise!
Summary
9. Database Transactions
Introduction to Database Transactions
The ACID properties
Importance of database transactions
Implementing a transaction
Transactions in Clojure
Transactions in YeSQL
Extending the application requirements in brief
Creating the add artist/album form
Creating the form
Abstracting the form
Creating the add artist/album endpoint
Creating the Compojure route
Creating the route helper function
Validating the add artist/album form
Expanding the album model
Wrapping the whole thing in a transaction
Using a transaction outside of this scope
Summary
10. Sessions and Cookies
Sessions
Setting up sessions
Interacting with the session
Restricted routes
Restricting route access
Accessing a restricted route
Access rule as a function
Access rule as a map
Cookies
Getting a cookie's value
Setting a cookie's value
Setting the cookie as a map
Securing a cookie
Deleting a cookie
Extending the application: brief requirements
Creating the login form
Restricting the recently-added route
Restricting the route
Checking if the user is authenticated
Defining the access rule
Authenticating the user
Validating the credentials
Handling the form POST
Writing the "Remember Me" cookie
Creating the logout route
Summary
11. Environment Configuration and Deployment
Environ
Using environ
Variable translations
Setting and resolving environment configurations
Resolving environment configuration
Adjusting the database connection
Creating the profiles.clj file
Modifying the hipstr.models.connection namespace
Deploying the hipstr application
When to use an uberjar
When to use an uberwar
Deploying as a standalone
Running the application behind Nginx
Load balancing behind Nginx
Summary
A. Using Korma – a Clojure DSL for SQL
Getting Korma
The Quick Korma Crash Course
Define the database specification
Korma entities
Defining the primary key
Defining relationships between entities
Constructing SELECT queries
Constructing INSERT queries
Constructing UPDATE queries
Constructing DELETE queries
Using raw SQL
Using transactions
Port the models from YeSQL to Korma
Porting hisptr.models.connection
Porting hisptr.models.user-model
Porting hipstr.models.album-model
Index

Clojure Web Development Essentials

Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedd...

Table of contents