Learning Ratpack
by Dan Woods
Copyright 2016 Dan Woods. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Editor: Brian Foster
- Production Editor: Nicole Shelby
- Copyeditor: Jasmine Kwityn
- Proofreader: Kim Cofer
- Indexer: Ellen Troutman
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Rebecca Demarest
Revision History for the First Edition
- 2016-05-27: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781491921661 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Learning Ratpack, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-491-92166-1
[LSI]
This book is dedicated to my wonderful wife, Ashley. Without her continued support and patience, Learning Ratpack would never have been possible. Thank you, Ashley, for the many wonderful years we have shared together and the many, many more to come.
This book is also for my children, Natasha and Ethan. Your love and smiles continue to drive me every single day. I could not have done this without you two; you are my world.
Foreword
If you want to know Ratpack, you have come to the right place. This book is the best and most comprehensive learning resource out there, and Dan is an integral part of the team and community behind Ratpack. I am thrilled that this book is now available.
There are many tools for writing web applications on the JVM, of which Ratpack is one. I set out to make Ratpack excel at scaling in all relevant ways. While performance and efficiency are crucial, the ability to start simple for greenfield tasks yet scale toward solving more challenging problems is equally important. You should feel as empowered by your tools after two years as you did after two days. This is Ratpacks mission, which Dan eloquently conveys.
We are now building, testing, and deploying web infrastructure differently than we were just a few years ago. Developers and users are, rightfully, more demanding than ever. Applications must integrate with and exist within an ever-shifting landscape of tools, practices, and platforms. Ratpack takes this to heart in several ways: it is a pure runtime in that it does not impose a proprietary mechanism for build automation, nor does it require proprietary plugins for IDE integration; it treats deep testability as a first-class concern; and it favors integration over abstraction, allowing more direct use of complementary technologies such as persistence, marshalling, and templating. This is a conscious trade-off of out-of-the-box magic for long term flexibility and control. Developer freedom is a key tenet of Ratpack. Admittedly, this may not be the most pressing concern for new (and simple, which all new projects inherently are) projects, but its important when things get real later in an applications life. And of course, there is performance.
The term performance can mean many things when it comes to web applications, and the most relevant meanings for the term are also shifting over time. We are now asking backend web applications to deal with more HTTP connections than ever, and to do it faster than ever. Moreover, as we deploy more and more of our applications to platforms where you pay for what you use, making efficient and predictable use of computing resources is becoming a primary concern for more teams. Ratpack uses event-driven I/O and asynchronous programming for this reason. More efficient and predictable use of computing resources means lower costs and reduced risk of emergency rearchitecting due to scaling limits.
Asynchronous programming brings its own set of challengesa key feature of Ratpack is the way in which it makes asynchronous programming more palatable. For many new to the paradigm, this is an area where guidance when getting started is particularly useful. This book does a great job in demystifying the what and the why of this, which is reason alone to read it.
As the creator of Ratpack, I want other developers to enjoy the same level of satisfaction I do when using it. More specifically, I want other developers to feel empowered but not constrained by it. This requires an understanding of what Ratpack can do for you, why and how it works, and what it leaves up to you.
Luke Daley
Preface
Ratpack has had a long and wonderful history as an open source web framework for the Java Virtual Machine (JVM). As a high-performance, reactive web framework, it brings forth the fundamental concept that building succinct, lightweight web applications is only truly serviced when matched with performance, efficiency, productivity, and testability as first-class features.
As systems infrastructure moves increasingly to the cloud, the need has never been more apparent for applications to be built in a way that utilizes system resources as efficiently as possible. Ratpacks emphasis on performance and efficiency means that robust web applications can be built to deliver high performance and low memory utilization. In this way, Ratpack aims to maximize your investment in compute resources, while facilitating a developer experience that is focused on productivity and risk reduction.
The need for high performance and efficient web applications means building asynchronous programming fixtures atop a nonblocking networking layer. The paradigms in asynchronous programming can be difficult for unacquainted developers to grasp, making web frameworks that build on these concepts unapproachable.
Indeed, even for the most seasoned of developers, asynchronous programming introduces a level of complexity that means the benefits must be carefully weighed against the increased cognitive overhead. With Ratpack, asynchronous programming is presented in a way that is meant to be digestible, with a drastically reduced cognitive load from developers.
Reducing complexity while increasing approachability also means allowing applications to be built in a semantic and expressive way. Web application concepts are easily expressed in Ratpack through a concise programming interface that works with web nomenclature that developers will be familiar with. To that extent, the simplest Ratpack application can be written in just a few lines of code, as we will explore at the beginning of .
Throughout Learning Ratpack, you will be taken on a progressively in-depth tour of the framework and its capabilities. With comprehensive demonstrations, you will leave every chapter with a working knowledge of the subject matter, and a foundation for a deeper understanding in subsequent chapters. You will be exposed to many aspects of the framework throughout, and by the end of the book, you will have the confidence to build production-grade web applications with Ratpack.