REST in Practice
Jim Webber
Savas Parastatidis
Ian Robinson
Copyright 2010 Jim Webber, Savas Parastatidis, and Ian Robinson
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (.
The OReilly logo is a registered trademark of OReilly Media, Inc., REST in Practice , the cover image, and related trade dress are trademarks of OReilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and OReilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
O'Reilly Media
Foreword
FROM THE VERY START OF WHEN I GOT INVOLVED IN COMPUTING, theres been the desire to have software systems designed as components that can be freely combined. The wide-scale connectivity of the Internet fueled this desire, and added the desire to have components operate over networks that introduce issues of latency and unknown reliability. In this world many systems have been tried, and many have failedusually with a whimper.
A great example of success is the World Wide Web. Its success has penetrated both business operations and popular culture. It provides opportunities for people to pull together information from many sources, with hardly any prearranged collaborationand at a global scale.
The Web, as we currently know it, isnt the be-all and end-all of computing, but many people believe it offers an important lesson on how to construct systems of networked components. Many people take advantage of its protocol, HTTP, to connect systems. But some people think we should go further, using HTTP not as a convenient tunnel, but to embrace the way the Web works as a foundation for systems collaboration.
This thinking gathers together under the name of REST. It refers to Roy Fieldings PhD thesis, which is far more often referred to than it is read. There is a growing notion that following the principles of REST offers a fruitful path to making networked components work, one that is built upon the success of the Web itself.
That vision is attractive, but there is much to be done to reach it. We have to take the principles of REST and see how to apply them to the everyday problems of systems integration. This is the task the authors of this book have taken on: to take REST from an attractive vision to implemented systems. Theyve done much to teach me about thinking in resources, how to use HTTP idioms, and the importance of hypermedia controls. As a result, this book will give you a thorough grounding in applying the core elements of RESTful thinking.
As we all should know, REST is not the answer to all questions. There are many situations where a REST approach is an appropriate approach, but many where it is not. As its early days in using this style for integration problems, we are still feeling our way around these boundaries. But in order to explore these boundaries properly, its vital to have a proper understanding of what REST is about. Without that, you run the risk of trying pseudo-REST and drawing the wrong conclusions. This book can help you avoid that fate.
Martin Fowler
August 2010
Preface
THE WEB HAS REVOLUTIONIZED THE WAY WE ACCESS AND SHARE INFORMATION. In just two decades, it has become the global platform for delivering and consuming services.
The pervasiveness and ubiquity of the Web stems from the way it combines architectural simplicity with a small set of widely accepted technologies. The Web provides scalability, security, and reliability for those systems that embrace its simple tenets, and it does so using commodity tools and platforms.
Our goal in this book is twofold: to demystify the Web as an application platform and to showcase how web architecture can be applied to common enterprise computing problems. Throughout the chapters, we make it a point to demonstrate how services can leverage the Web both inside and outside enterprise boundaries. Our vision is of an information platform that is open and available to other systems, which eschews integration in favor of composition, and yet implements valuable business behaviors: a distributed, hypermedia-driven application platform.
You dont have to know REST or HTTP in detail in order to understand this book. Well take you from simple integration through to sophisticated business protocols, all with detailed code examples that you can adapt for your own ends.
Should I Read This Book?
Like most of us, youre probably already building something that feeds into the Web, and youve probably used tools and patterns for the Web that seem pretty useful. Then youve tackled typical enterprise problems and wondered why it cant be as nice as the web stuff.
Youre seeing the benefits of the Web all around and you start to question whether your enterprises expensive middleware offers a good return on investment, or whether it will ever scale to meet your users demands.
You might be a developer who wants to understand the Webs principles in more detail, and likes to learn through code examples. Youve heard terms such as URIs, HTTP , and Atom , and you want to learn more about them, including the type of support you can get from popular programming platforms.
You may even be an enthusiast who has heard about REST and wants to know what it is all about. You want to learn more about hypermedia and the REST architectural style so that you can build resource-oriented systems and implement sophisticated business protocols atop the Web.
This book will help.
Should I Skip This Book?
If you are looking to learn how to design websites or how to write JavaScript applications, this book will not offer you much, though theres plenty for competent AJAX developers to leverage from our approach to building backend services.
If you are looking to build mashups or systems for people to use directly, this book is probably not for you. Weve focused on machine-to-machine interactions. In fact, this book is full of machines talking to one another through the Web.
We rather like it that way.
Resources
The book is accompanied by a website: http://restinpractice.com. There youll find working code samples from the book, links to other resources, errata, and community information. We will make every effort to continuously update the site with more information.
What Did You Think About the Book?
We are very interested in your thoughts on this book, positive or negative. You can head to Amazon and share your thoughts by writing a review. Alternatively, OReilly would be more than happy to hear your views at:
http://www.oreilly.com/catalog/9780596805821/
Errata
While we have made every effort to keep the book error-free, we have probably missed a few things. Errata give readers a way to let us know about typos, errors, and other problems with the book. You can head to the books URI at OReilly in order to let us know. Wed really appreciate it:
http://www.oreilly.com/catalog/9780596805821/