Restlet in Action:
Developing RESTful web APIs in Java
Jerome Louvel, Thierry Templier, and Thierry Boileau
Copyright
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact
Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email:
orders@manning.com2013 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.
| Recognizing the importance of preserving what has been written, it is Mannings policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. |
| Manning Publications Co.20 Baldwin RoadPO Box 261Shelter Island, NY 11964 | Development editor: Jeff BleielCopyeditor : Corbin CollinsProofreaders : Elizabeth Martin, Melody DolabTypesetter : Dennis DalinnikCover designer : Marija Tudor |
ISBN: 9781935182344
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 MAL 18 17 16 15 14 13 12
Dedication
To my father, Guy Louvel, for his love of life and people and for inspiring my passion for computers
J.L.
Brief Table of Contents
Table of Contents
Foreword
News flash: the web is kind of a Big Deal.
It is difficult to consider its full impact on technology, society, commerce, education, governance, and entertainment without resorting to grand language that has been stated many times before. It is a Big Deal and we will never be the same because of it.
But, heres the thing. If we sat down and tried to rebuild the web today, knowing what we know from 20 years of experience with it, we would probably fail. The problem is that as software developers, we generally think in terms of software constructs: objects, services, methods, etc. While useful from a solution space perspective, they can induce coupling and coupling does not scale.
The web works because in its design, Sir Tim Berners-Lee and his cohorts embraced the notion of change. The thing we forget is that they were not trying to build the web that we know; they were trying to build a system that worked for a dynamic organization such as CERN. Logically named resources could be requested and manipulated with no regard to how back-end systems worked. New shapes of information could be negotiated over time without disrupting deployed systems. Clients and servers could evolve independently.
The REpresentational State Transfer (REST) architectural style embraced these ideas and began to describe how to build flexible, scalable, change-tolerant systems. The primary shift was away from implementation details and toward the information that flows through the infrastructure. Clients were less cognizant of what to expect and more reactive to what they were told. The focus was on the properties induced by the architectural choices, not the technologies used to implement the solutions.
This is an important point because most REST frameworks built in languages such as Java ignore these distinctions. Their choices reflect a desire to bend REST to a privileged Java world view, not the other way around. What makes REST special and interesting is lost in the process, which is why I think most of them ultimately fail. Jrmes work on Restlet struck me as having the appropriate perspective: how can we conveniently surface the ideas of REST in a language like Java without debasing the goals of the architectural style.
He tackled the problem from both the client and the server perspectives. He introduced objects that stood for a Resource itself. He turned concepts such as content negotiation and metadata management into registered services, outside of the concerns of these resources. He embraced the idea of logically named protocols to extend the idea of REST into the framework with tools like the Restlet Internal Access Protocol (RIAP) and the Class Loader Access Protocol (CLAP). He understood the value of getting the APIs to a consistent, uniform place before declaring success. The resulting framework is cleaner, more flexible, and more true to the spirit of REST than any other language-based approach I have seen.
While the Restlet documentation has always been adequate, as I introduced the API in my talks and courses, I longed for a solid book on the subject. I even toyed with the idea of writing one. Thankfully, now, as I look at the manuscript in front of me, I do not have to.
Restlet in Action by Jrme et al. is exactly the broad, deep, and example-driven book I had hoped for. The list of topics they tackle is impressive. The authors provide thorough but not overwhelming coverage of REST itself, security, and performance. Beyond that, they also discuss issues of growing interest such as mobile applications, the cloud, the Semantic Web, Linked Data, and the future of HTTP. The whole endeavor is grounded in practical advice on how to use Restlet toward those ends. These ideas are a Big Deal and this book will help you understand why and how to benefit from them.
I have already preordered Restlet in Action for many of my clients and students and anticipate it being a staple in my courses for years to come.
B RIAN S LETTEN
P RESIDENT
B OSATSU C ONSULTING , I NC .
Preface
When I had a chance to use the Mosaic web browser way back in 1994, I fell in love with the web at first sight and became interested in HTML and the way the W3C was driving the growth of the web along with the IETF. A year later, I discovered Java by reading Suns white paper and was convinced that it would lead to a great future. I started using it professionally to write a web load-testing tool using CORBA and an HTTP proxy.
In 2001, while reading Weaving the Web by Tim Berners-Lee, I was hooked by his grand vision of a read-write Semantic Web and started to think about the best way to help it come about. In 2004, I built a website in my spare time called Semalink which bridged the classic web of documents with the semantic web of data. As I wanted to stay true to the principles of the web, I read more and more about REST and the core HTTP and URI standards and realized that the Servlet API had too large a gap applying those principles. Thats when Restlet emerged as a higher-level Java API derived directly from REST and HTTP. This was very helpful, so I thought about sharing it with others. I believed that it could radically change the way we develop web applications, in the same way that REST was radically changing the way I was thinking about the web.
After announcing the Restlet Framework on December 2005 in an article on TheServerSide website, I hoped that this open source project, the first REST framework for Java, would contribute to the success of REST in the Java world. I wasnt sure how the Java community would welcome it since the industry was strongly behind Java EE (including Servlet, JSP, and Spring MVC) and WS-* (based on the SOAP protocol) technologies.