Learning Ratpack: Simple, Lean, and Powerful Web Applications

Learning Ratpack: Simple, Lean, and Powerful Web Applications

by Dan Woods

Paperback

$44.99 $49.99 Save 10% Current price is $44.99, Original price is $49.99. You Save 10%.
View All Available Formats & Editions
Choose Expedited Shipping at checkout for guaranteed delivery by Thursday, October 17

Overview

Build robust, highly scalable reactive web applications with Ratpack, the lightweight JVM framework. With this practical guide, you’ll discover how asynchronous applications differ from more traditional thread-per-request systems—and how you can reap the benefits of complex non-blocking through an API that makes the effort easy to understand and adopt.

Author Dan Woods—a member of the Ratpack core team—provides a progressively in-depth tour of Ratpack and its capabilities, from basic concepts to tools and strategies to help you construct fast, test-driven applications in a semantic and expressive way. Ideal for Java web developers familiar with Grails or Spring, this book is applicable to all versions of Ratpack 1.x.

  • Configure your applications and servers to accommodate the cloud
  • Use Ratpack testing structures on both new and legacy applications
  • Add advanced capabilities, such as component binding, with modules
  • Explore Ratpack’s static content generation and serving mechanisms
  • Provide a guaranteed execution order to asynchronous processing
  • Model data and the data access layer to build high-performance, data-driven applications
  • Work with reactive and functional programming strategies
  • Use distribution techniques that support continuous delivery and other deployment tactics

Product Details

ISBN-13: 9781491921661
Publisher: O'Reilly Media, Incorporated
Publication date: 06/25/2016
Pages: 368
Product dimensions: 6.90(w) x 9.10(h) x 0.80(d)

About the Author

Dan Woods is an open source enthusiast and a member of the Ratpack core team. His professional life focuses on building and architecting scalable distributed systems for cloud runtimes.

Table of Contents

Foreword ix

Preface xi

1 Welcome to Ratpack 1

Hello, World! 2

Running the Example 3

Rapid Prototyping 4

Handler Chain 5

URL Path Bindings 5

Prefixed Routes 7

Path Tokens 8

Request Parameters 9

Parsing Request Data 10

Content Negotiation in Handlers 11

Chapter Summary 18

2 Getting Started 19

Library Structure 20

Project Structure 21

Ratpack Cradle Plugin 22

Cradle Wrapper 28

Hot Reloading 30

Lazybones 30

Building from a Main Class 33

Working with Handlers 35

Understanding the Chain API Interactions in Groovy and Java 35

Standalone Handlers 36

Chapter Summary 41

3 Testing Ratpack Applications 43

Spock Test Structure 45

Functional Testing 48

Bootstrapping Test Data 53

Architecting for Improved Testability 55

Integration Testing 58

Unit Testing 61

Unit Testing Standalone Handlers 63

Other Testing Scenarios 68

Chapter Summary 75

4 Application Configuration 77

Configuring with Environment Variables and System Properties 87

Configuring with Environment Variables 88

Configuration with System Properties 90

Nested Configuration Models 92

Custom Configuration Source 95

Setting Server Configuration 99

Chapter Summary 101

5 Ratpack Modules 103

Extending Ratpack with Registries 104

Google Guice 108

BindingsSpec in Groovy 111

Framework Modules 117

Configurable Modules 119

Modular Object Rendering in Ratpack 124

Rendering with Content Type 126

Rendering JSON Data 127

Special Rendering Scenarios 128

Chapter Summary 129

6 Serving Web Assets 131

Serving Static Content 131

Caveats to the FileHandler 134

Using FileSystemBinding to Customize Asset Resolution 135

Serving Dynamic Content 139

Handlebars.js Support 141

Thymeleaf Support 143

Groovy Markup Templates 145

Conditionally Serving Content 147

Conditionally Scoping Resources 147

Conditionally Serving Assets Based on Request Attributes 151

Sending Files from Handlers 152

Customizing 404 Behavior 153

Cache Control 155

Asset Pipeline 157

Chapter Summary 160

7 Asynchronous Programming, Promises, and Executions 161

Promises: A Better Approach to Async Programming 164

Execution Model 166

Scheduling Execution Segments for Computation or I/O 167

Leveraging Executions on Unmanaged Threads 170

Error Handling 172

Execution-Wide Error Handling 173

Promise Error Handling 175

Creating Promises on Your Own 176

Promises from Synchronous Calculations 177

Promises from Asynchronous Calls 178

Chapter Summary 181

8 Data-Driven Web Applications 183

Groovy SQL Support 183

Connection Pooling with HikariCP Support 190

Ratpack and Grails GORM 195

Designing Data-Driven Service APIs in Ratpack 207

Chapter Summary 211

9 Ratpack and Spring Boot 213

Adding Spring Boot to Your Ratpack Project 218

Creating a Spring Boot-Backed Registry 221

API Design with Ratpack and Spring 227

Other Notes on API Design with Ratpack and Spring 229

Known Limitations 232

Chapter Summary 232

10 Reactive Programming in Ratpack 233

Overview of Reactive Programming 233

Promise as a Reactive Data Structure 236

Transforming Data with Promises 239

Filtering Data with Promises 240

Composing Data with Promises 242

Reactive Streams 244

Publishers and bindExec 248

RxTava 248

Parallel Processing Using Rxjava 256

Further Reading on Rxjava 258

Chapter Summary 259

11 Sessions and Security 261

Integrating Session Support 261

Persisting Objects 264

Configuring the Session Module 267

Client-Side Sessions 268

Distributed Sessions 271

Working with Cookies 273

Tuning Cookies 277

Expiring Cookies 279

Chapter Summary 283

12 Application Security 285

SSL Support 285

Basic Authentication 290

Custom UsernamePasswordAuthenticator 295

Form-Based Authentication 301

Data-Driven Form Authentication 306

Additional Authentication Means 312

Chapter Summary 313

13 Going to Production 315

Publishing Metrics 315

Enabling Reporting 317

Publishing Custom Metrics 320

Application Health Checks 321

Building Distributions 331

Production Checklist 333

Chapter Summary 333

Index 335

Customer Reviews

Most Helpful Customer Reviews

See All Customer Reviews