Supplemental files and examples for this book can be found at http://examples.oreilly.com/9780596529260/. Please use a standard desktop web browser to access these files, as they may not be accessible from all ereader devices.
All code files or examples referenced in the book will be available online. For physical books that ship with an accompanying disc, whenever possible, weve posted all CD/DVD content. Note that while we provide as much of the media content as we are able via free download, we are sometimes limited by licensing restrictions. Please direct any questions or concerns to .
Foreword
David Heinemeier Hansson
The world of web services has been on a fast track to supernova ever since the architect astronauts spotted another meme to rocket out of pragmatism and into the universe of enterprises. But, thankfully, all is not lost. A renaissance of HTTP appreciation is building and, under the banner of REST, shows a credible alternative to what the merchants of complexity are trying to ram down everyones throats; a simple set of principles that every day developers can use to connect applications in a style native to the Web.
RESTful Web Services shows you how to use those principles without the drama, the big words, and the miles of indirection that have scared a generation of web developers into thinking that web services are so hard that you have to rely on BigCo implementations to get anything done. Every developer working with the Web needs to read this book.
Preface
A complex system that works is invariably found to have evolved from a simple system that worked.
John GallSystemantics
We wrote this book to tell you about an amazing new technology. Its here, its hot, and it promises to radically change the way we write distributed systems. Were talking about the World Wide Web.
Okay, its not a new technology. Its not as hot as it used to be, and from a technical standpoint its not incredibly amazing. But everything else is true. In 10 years the Web has changed the way we live, but its got more change left to give. The Web is a simple, ubiquitous, yet overlooked platform for distributed programming. The goal of this book is to pull out that change and send it off into the world.
It may seem strange to claim that the Webs potential for distributed programming has been overlooked. After all, this book competes for shelf space with any number of other books about web services. The problem is, most of todays web services have nothing to do with the Web. In opposition to the Webs simplicity, they espouse a heavyweight architecture for distributed object access, similar to COM or CORBA. Todays web service architectures reinvent or ignore every feature that makes the Web successful.
It doesnt have to be that way. We know the technologies behind the Web can drive useful remote services, because those services exist and we use them every day. We know such services can scale to enormous size, because they already do. Consider the Google search engine. What is it but a remote service for querying a massive database and getting back a formatted response? We dont normally think of web sites as services, because thats programming talk and a web sites ultimate client is a human, but services are what they are.
Every web applicationevery web siteis a service. You can harness this power for programmable applications if you work with the Web instead of against it, if you dont bury its unique power under layers of abstraction. Its time to put the web back into web services.
The features that make a web site easy for a web surfer to use also make a web service API easy for a programmer to use. To find the principles underlying the design of these services, we can just translate the principles for human-readable web sites into terms that make sense when the surfers are computer programs.
Thats what we do in this book. Our goal throughout is to show the power (and, where appropriate, the limitations) of the basic web technologies: the HTTP application protocol, the URI naming standard, and the XML markup language. Our topic is the set of principles underlying the Web: Representational State Transfer, or REST. For the first time, we set down best practices for RESTful web services. We cut through the confusion and guesswork, replacing folklore and implicit knowledge with concrete advice.
We introduce the Resource-Oriented Architecture (ROA), a commonsense set of rules for designing RESTful web services. We also show you the view from the client side: how you can write programs to consume RESTful services. Our examples include real-world RESTful services like Amazons Simple Storage Service (S3), the various incarnations of the Atom Publishing Protocol, and Google Maps. We also take popular services that fall short of RESTfulness, like the del.icio.us social bookmarking API, and rehabilitate them.
The Web Is Simple
Why are we so obsessed with the Web that we think it can do everything? Perhaps we are delusional, the victims of hype. The web is certainly the most-hyped part of the Internet, despite the fact that HTTP is not the most popular Internet protocol. Depending on whos measuring, the bulk of the worlds Internet traffic comes from email (thanks to spam) or BitTorrent (thanks to copyright infringement). If the Internet were to disappear tomorrow, email is the application people would miss the most. So why the Web? What makes HTTP, a protocol designed to schlep project notes around a physics lab, also suited for distributed Internet applications?
Actually, to say that HTTP was designed for anything is to pay it a pretty big compliment. HTTP and HTML have been called the Whoopee Cushion and Joy Buzzer of Internet protocols, only comprehensible as elaborate practical jokesand thats by someone who likes them.[]The first version of HTTP sure looked like a joke. Heres a sample interaction between client and server: