6.2 What Are Web Services?

Web Services are essentially nothing new. They've existed in various forms ever since research groups and businesses started networking online to exchange data. These machine-readable requests were built on an ad hoc basis with whatever tools were standard in the companies at the time, and then replaced or obfuscated with layer upon layer, hack upon hack. This was a rather costly and not particularly pretty state of affairs; furthermore, each Web Service was unique and not easily adaptable or interoperable with additional parties and other services.

Perhaps the first truly "Web" service was a combination of spidering and scraping. The Web introduced a presentation markup language called HTML, which allowed you to represent data in a form that was readable by a web browser and that was, for the most part, pleasing to the person browsing. By scraping (reading between the bits of HTML markup), you could get to the underlying data; by doing so programmatically (spidering), you could automate this process.

So with the increasing number of database-backed web sites appearing on the Web in the mid-90s, people had an enormous data set at their disposal. With just a little programmatic elbow grease, you could search the Web, track stocks, read the news, etc. But scraping is a brittle process?it relies upon the layout of a site remaining fairly static, and the programmer maintaining the scraper needs to make alterations as a site bolds this, italicizes that, and so forth. And it becomes even more complicated with the advent of more complex HTML, cookies, and interactivity in web pages.

Web Services as we think of them today are an agreed-upon standard for describing data with XML that allows programs on separate servers to communicate and share information through the Web. Even though different companies have been involved in the development of Web Services, no one company owns or controls the standard. As with the Web itself, this openness allows anyone to build applications or tools that use the standard in their preferred programming language for any computing platform. Web Services are a way of opening an Application Programming Interface (API), and I'll use these two terms interchangeably.

At the most basic level, Web Services are simply XML sent over a transport medium, usually HTTP. XML is a textual representation of data capable of describing rich data sets, and HTTP (the standard language spoken by web servers for brokering requests for web pages and associated media) is the method of transporting it over the Internet. In a typical Web Services application, one computer makes a request for data, and another computer sends a response. A few different XML formats and methods of sending requests and responses exist within the Web Services arena. Simple Open Access Protocol, or SOAP, provides a standard framework for sending XML requests and responses. Each request describes exactly what it's requesting, and the response is similarly structured. REST (also called XML/HTTP), on the other hand, is a way of requesting an XML document with a URL, just as you request web pages. The debate among developers about which method is best has an almost religious fervor.

The emergence of these Web Services standards has enabled large, consumer-focused businesses to begin offering Web Services to the public. Google is generally considered the first broad-scale Web Service opened to developers for experimentation. Although the Google Web API (http://apis.google.com) sports a massive data set?their entire web search index?it isn't quite as rich as the one provided by the Amazon Web Services program. The latter provides not just a simple search interface to Amazon products, but a rich programmatic interface to the vast majority of the functionality explored in this book.

New developer tools, the likes of Amazon and Google opening their data sets to programmatic interaction, and a wide base of developers who understand the technology have allowed Web Services to leave the dry world of business-to-business communications and enter a new arena of experimentation, both technical and business-based.