Book Image

Lift Application Development Cookbook

By : Gilberto Tadeu Garcia Jun
Book Image

Lift Application Development Cookbook

By: Gilberto Tadeu Garcia Jun

Overview of this book

Developing secure web applications is one of the most important tasks developers have to deal with. With Lift, it is easy to create solid and formidable web applications as it is the most secure web framework available today. The View-First approach and being able to handle things as purely data transformation, makes working with Lift an exciting task. "Lift Application Development Cookbook" teaches you how to build web applications using this amazing framework. The book moves gradually, starting with the basics (starting a new project, submitting a form, and so on) before covering more advanced topics such as building a REST API and integrating your application with other technologies and applications. "Lift Application Development Cookbook" takes you on a journey of creating secure web applications. Step-by-step instructions help you understand how things work and how various elements relate to each other. You'll learn different ways to process a form, build dynamic HTML pages, and create an API using REST. You'll also learn how to work with relational and NoSQL databases and how to integrate your application with other technologies as well as with third-part applications such as Gmail and Facebook. By the end of the book, you will be able to understand how Lift works and be able to build web applications using this amazing and exciting framework.
Table of Contents (15 chapters)
Lift Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Lift is a web framework built in Scala. Its main goal is to be a secure framework that helps developers to build scalable web applications in a concise and maintainable way.

There are six things—according to the official website, http://liftweb.net/—that makes Lift different from any other web framework available today:

  • Secure: Lift apps are resistant to common vulnerabilities, including many of the OWASP Top 10 projects

  • Developer-centric: Lift apps are fast to build, concise, and easy to maintain

  • Designer-friendly: Lift apps can be developed in a totally designer-friendly way

  • Scalable: Lift has a number of high-performance apps, and they scale in the real world to handle insane traffic levels

  • Modular: Lift apps can benefit from easy-to-integrate, pre-built modules

  • Interactive like a desktop app: Lift's Comet support is unparalleled, and Lift's Ajax support is super easy and very secure

The goal of this book is to introduce you to the basics of Lift, and teach you everything that you need to know to build applications using Lift.

By providing you with hands-on examples, we hope that you find this book useful as your first introduction to Lift, and also as a reference guide when building your own web applications.

What this book covers

Chapter 1, Getting Started with Lift Basics, covers the basics of Lift which include how to start a new application using build tools such as SBT and Maven. It also explains how to define the application structure using SiteMap object and how to use the Mailer object to send e-mails.

Chapter 2, Working with HTML, introduces the reader to CSS selectors and shows how to use them to transform the HTML that will be rendered in the browser. It also covers how to test snippets, how to generate a JavaScript code from the server, and how to invoke server-side functions using JavaScript. It also explains how to localize templates.

Chapter 3, Working with Forms, covers the different ways the reader can work with forms, such as how to create a single page form and a wizard-like form. It also explains how to submit forms using Ajax and how to wire form fields.

Chapter 4, Working with REST, introduces Lift's RestHelper object and how to use it to create a REST API. It also explains how to test the REST API, how to upload files, and how to create an RSS feed.

Chapter 5, Working with Databases, explains how to use Mapper to integrate the application with a database. It also covers the basics of ORM mapping and how to use an in-memory database to test an application that uses Mapper.

Chapter 6, Working with Record, explains how to integrate a Lift application with a database using Record and Squeryl. It also covers how to test an application that uses Record and Squeryl using an in-memory database.

Chapter 7, Working with MongoDB, covers the integration of a Lift application with MongoDB, how to use Record to create such an integration, and explains how to query MongoDB using Rogue.

Chapter 8, Integrating Lift with Social Media, explains how to use social login to authenticate users and how to get their data from their Facebook, Gmail, Twitter, or LinkedIn accounts.

What you need for this book

To be able to follow the recipes, you will need to have Java 7 installed on your computer.

Who this book is for

This book is for developers who want to learn how to develop web applications using the Lift framework. However, we assume that the reader at least knows the basics of Scala, HTML, and JavaScript.

Conventions

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 an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The bigger difference lies in the snippet code. You can see that after getting the user data, we've invoked a method called fetchUserData and used its result to change the contents of a li tag."

A block of code is set as follows:

import code.lib.googleSession
import net.liftweb.util.BindHelpers._
import net.liftweb.common.Full

object GmailData {
  def render = {
    googleSession.get match {
      case Full(email) => ".email" #> email
      case _ =>  "*" #> "Not authorized"
    }
  }
}

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

        <pubDate> {longDate(Calendar.getInstance().getTimeInMillis)} </pubDate>
        {ClientCache.clients.flatMap {
        c =>
          <item>
            <title>Client: {c.id}</title>
            <description>Name: {c.name} - E-mail: {c.email}</description>

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

scala> val transformSpanContent = "span *" #> "Some Text"

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: "If you select a name in the combobox and click on the Delete Selected button, you'll see an alert saying that the name you selected was deleted."

Note

Warnings or important notes appear in a box like this.

Tip

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 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 on www.packtpub.com/authors.

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 for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

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 would 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 http://www.packtpub.com/submit-errata, 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 on 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 http://www.packtpub.com/support.

Piracy

Piracy of copyright 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.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.