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

Getting data from the server


In this recipe, we will learn how to build URLs to respond to GET requests. In other words, we will learn how to serve data to the clients of your API. This means that you will be able to create a REST URL, where you can fetch a collection from data of a given resource—data about clients in this case—or fetch data about a specific resource.

Getting ready

You can either use example codes, which we have used in the recipes from previous chapters, or you can start a new project.

After creating the project, we will need to create a list of clients to serve as an in-memory database. We will need a model class to keep the data that will be shown on the page:

  1. Inside the code.model package, let's create a class named Client with the following code:

    package code.model
    
    import net.liftweb.json.JsonDSL._
    
    case class Client(id: Int, name: String, email: String) {
      def asJson = {
        ("id" -> id) ~
          ("name" -> name) ~
          ("email" -> email)
      }
    }
  2. Let's create a...