ltr: Vol. 42 Issue 3: p. 19
Chapter 2: Examples of Web Services : Amazon and Google
Marshall Breeding

Abstract

“In an era of computing dominated by the World Wide Web, technology referred to as Web services stands as a key one for allowing computers to communicate machine to machine, program to program.…Web services make it easy to connect all types of computer applications to each other. As you will see throughout this report, Web services deliver a foundation of interoperability greatly needed in a world where computer services and digital information exist in many different forms and flavors,” says Breeding in his “Introduction” in the latest issue of Library Technology Reports, “Web Services and the Service-Oriented Architecture.”

“If, in the future, libraries want to be isolated islands in the ocean of content and information, they can ignore Web services. But because much of what libraries do centers on providing information to library clientele and because information is increasingly more electronic—which causes libraries to overlap with many other organizations in the information sphere—it is necessary for libraries to cooperate and interact with a broad set of other organizations and their technical infrastructures. Web services provide mechanisms that allow libraries to expand their services in many important ways.”—Marshall Breeding, “Web Services and the Service-Oriented Architecture.”

About the Author

Marshall Breeding is Director for Innovative Technologies and Research for the Jean and Alexander Heard Library at Vanderbilt University and is responsible for strategic planning for technology and digital library projects. He also serves as the Executive Director and Chief Technology Officer of the Vanderbilt Television News Archive. In his twenty years at Vanderbilt, he has been involved with network administration, library automation, database development, and a wide array of technology projects. In addition, has served as principal investigator on grants from the National Science Foundation and the National Endowment for the Humanities.

In addition to his work at Vanderbilt, Breeding is an eminent independent consultant, analyst, and writer in the fields of networking and library automation. He is a regular speaker and teacher at library conferences, having given more than one hundred presentations or workshops. Breeding has authored the annual “Automated System Marketplace” feature in Library Journal for the last four years; is a contributing editor to Smart Libraries Newsletter; is author of the Sep/Oct 2005 (41:5) issue of Library Technology Reports, “Wireless Networks in Libraries,” published by ALA TechSource; and writes the “Systems Librarian” column published monthly in Computers in Libraries.

According to Breeding, “Web Services and the Service-Oriented Architecture” aims to provide information about Web Services to a library audience. The report includes conceptual descriptions of the technology as well as some technical information on how Web services are implemented. “Library administrators or others that need to make decisions regarding library-related technology systems or issues will gain a perspective on the importance of this technology as well as how the implementation of Web services may relate to other library trends and initiatives. Library technical staff will gain from both the conceptual descriptions and the implementation examples.”


Real-world Web services will be examined in this chapter. This section is a bit more technical than other parts of the report, but nontechnical readers should not be intimidated by the programming code listed in the examples. Even nonprogrammers should be able to understand the gist of what these programs are trying to accomplish without having to have a keen grasp on the programming language. (I ask that programmers reading this report to bear with my unsophisticated programming style; more experienced programmers would write much more elegant code than my admittedly awkward efforts.)


Amazon Web Services

Amazon, one of the most popular commercial online businesses, offers a Web-service interface that provides a number of interesting features. The possibilities range from simple queries out of the Amazon catalogs to full-fledged e-commerce Web sites that operate in partnership with Amazon through the company's Amazon affiliates program.

Amazon.com has grown to be one of the most successful businesses on the Web. The company quickly established itself as a popular source for buying books on the Web and has expanded to sell many other types of products. In support of its extremely high-volume business, Amazon has developed a sophisticated, scaleable, and reliable technology infrastructure. On its own, Amazon is extremely successful, but an important part of its business strategy involves the company's efforts to go beyond its direct sales and to include affiliates and partners. For example, Amazon allows other individuals and organizations to make use of its infrastructure to sell their products and services in return for it receiving a small commission on each sale. This arrangement has proven to be beneficial for both Amazon and its affiliates. An individual or business can fairly easily set up his, her, or its own electronic storefront; this storefront features the e-commerce capabilities developed by Amazon, which would be much more difficult and expensive to create independently.

The mechanism that Amazon uses for expanding its online-business activities is based on Web services. Using Web-service technologies described in this report, Amazon Web Services (AWS) provide access to Amazon's technical infrastructure. AWS can be implemented using either SOAP or REST, but the majority of AWS implementations follow the simpler REST approach.

In order to begin using AWS, one must first set up an AWS developer account. Once registered, the user will receive a subscription ID, which will be used as a key to gain access when invoking Web services. Many of the Web services offered by Amazon can be used for free, although some require paid subscriptions or involve pay-per-use fees.

The core functionality of Amazon.com can be programmatically accessed through the Amazon E-Commerce Service (ECS). Amazon does not charge for use of ECS, though some restrictions apply regarding how information retrieved from Amazon in this way may be used and the number of transactions performed per second. (The WSDL [Web Services Description Language] that describes the ECS is available at:http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl.)

Amazon offers extensive tools and documentation for building applications using AWS (http://aws.amazon.com). There are also a number of books and other resources available that provide extensive information on implementing applications based on AWS.

In the following text, I'll construct a very simple example that makes use of the Amazon Web Service (see appendix 3). The example will explain how the AWS functions to dynamically execute a search on Amazon—with a few lines of programming—to display the results.

Amazon E-Commerce Service http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl

Amazon Web Services http://aws.amazon.com

This, and most of the other examples in this report, will use the Perl programming language, for no other reason than it is the one with which I am most comfortable. The platform for the examples consists of the following components:

  • An Intel-based server running Windows XP Professional;
  • The Perl programming language. (I will use ActivePerl [available from ActiveState Software, Inc., www.activestate.com] ActiveState makes ActivePerl freely available and sells professional programming products and services);
  • The SOAP::Lite Perl module; and
  • The Internet Information Server (IIS) v5.0. This Web server comes as an optional component of Windows XP Professional.

A good resource for guidance in developing applications with AWS is Amazon Hacks by Paul Bausch. The following example is loosely based on a program, “Hack88: Program AWS with SOAP::Lite and Perl,” in the book

Building a Web-Service Client

Appendix 3 illustrates the Perl script that implements a Web-service client, a SOAP interface, which is used to send a service request to AWS, to perform an author query, parse the service response, and display selected elements on a Web page.

This script resides in a directory on the server that's configured to execute CGI-style programs. The value of the author to search is passed on as a parameter in the URL: www.family-photos.info/amazon-web-service .pl?Author=Marshall%20Breeding. When a Web browser invokes this script, it produces the Web page shown in appendix 4.

Breaking it down into steps may also help nontechnical individuals understand the general components.

First, appendix 5 illustrates the code that “calls in” some subroutines, which provide some general utility functions available for setting up Web pages and user sessions on a server. One of the subroutines available, &pagetop, issues an HTML header and begins a Web page.

The next section shows how the code sets things up to begin using SOAP, which will issue the request and receive the response. Perl::Lite supports WSDL, so it simply points to the AmazonWebService.wsdl file that defines the service and lets it do all the work of informing the client about the data types, messages, methods, and bindings that comprise the service.

Appendix 6 shows how the client will send a query to AWS to search by author. In this figure, a variable—$query—is set up to pass the value of the query. The diglib-common.pl file (see appendix 3) also contains the code to parse parameters on the command line and puts them into an associative array named fields. In the example in appendix 6, $fields{‘Author’} will take the value “Marshall Breeding” as specified in the Author=Marshall Breeding component of the URL.

The next portion of the script, shown in appendix 7, does the heavy lifting. It invokes the method AuthorRequest defined in the WSDL and passes on the appropriate parameters.

The AuthorRequest method in the Perl script corresponds to the way the AuthorRequest data type has been defined in the WSDL (appendix 8).

Once the service has been invoked and a response is received, that data returned can be parsed and will display the results, as implemented in the lines of Perl illustrated in appendix 9.

This simple example illustrates how one can draw information from a given resource and display that information in an interface. Although Amazon.com certainly looks much better than the simplistic interface demonstrated, the point is that the user is now able to use the content returned in whatever form his or her application might need. The script in appendix 3 builds a Web page that displays content from just the one source, but a more interesting example might involve using Web services from multiple sources. This is often called a mashup.


The GoogleSearch API

Google also provides a SOAP-based API for accessing its resources in a model for Web services. The Google API can be used to programmatically access several different services, including executing a search on Google and receiving the results, requesting a spelling suggestion, and fetching a cached page.

Just like Amazon, in order to use the Google Web API, you must create a Google account and receive a key that is passed with each request. Google provides information on its APIs at www.google.com/apis/index.html. The WSDL file that describes the Google Web API can be displayed with this URL: http://api.google.com/GoogleSearch.wsdl.

Google Web API www.google.com/apis/index.html

WSDL File Describing Google Web API http://api.google.com/GoogleSearch.wsdl

ActiveState offers the Perl module GoogleSearch .pm, which implements a SOAP interface to the methods available in the Google API. Appendix 10 is based on the ActiveState GoogleSearch.pm module. The GoogleSearch pm does not use the WSDL; rather the methods and data structures known to exist in the API have been hard coded into the module, yet there are many similarities to the Amazon search examples.

When invoked, the script creates a Web page such as the one shown in appendix 11. Again, this demonstrates how a user can programmatically access a remote service using a Web service, obtain content from that service, and display the content in the way the user desires.

The same results can be accomplished without the GoogleSearch.pm Perl module. Instead, the user would simply use SOAP::Lite directly and link it to the GoogleSearch.wsdl. The alternate version of the script is shown in appendix 12.


Appendix 3: SOAP Interface Example

Appendix 4: AWS Web Service Example

Appendix 5: Code That “Calls in” Subroutine for HTML Header and Beginning of Web Page

Appendix 6: Script Utilized for Client to Send Query to AWS to Search by Author

Appendix 7: Script That Invokes AuthorRequest, Defined in WSDL

Appendix 8: AuthorRequest Method in Perl Script Corresponds to AuthorRequest Data Type (in WSDL)

Appendix 9: Display Results

Appendix 10: Script Based on ActiveState GoogleSearch.pm Module

Appendix 11: Web Page Displayed by the Embedded Google Search Client

Appendix 12: SOAP::Lite Client Alternate Script That Yields Web Page Shown in Appendix 11

Article Categories:
  • Information Science
  • Library Science

Refbacks

  • There are currently no refbacks.


Published by ALA TechSource, an imprint of the American Library Association.
Copyright Statement | ALA Privacy Policy