Amazon Web Services
Amazon was one of the first companies to begin working with Web services. AWS is now a suite of different APIs, some of which have to do with Amazon's catalogs, and others (for example, the Mechanical Turk and Amazon's Simple Queue Service) are more generalized services. The most popular service is known as the E-Commerce Service (ECS). ECS makes it possible to retrieve product data from several of Amazon's stores, get detailed information about particular items and vendors, and also perform basic operations having to do with e-commerce, including the creation and manipulation of shopping carts.
ECS has two basic modes of operation, known as search and lookup. Searches return a list of products matching a set of criteria—for example, all of the books written by Larry Wall, or books with the word Python in the title or movies directed by Woody Allen. Lookups are meant for when you know the specific ID code associated with a product, known as an ASIN (Amazon Standard ID Number). The ASIN for books is the same as its International Standard Book Number (ISBN); other types of products have ASINs defined by Amazon.
So, let's say I'm interested in finding out whether Amazon stocks the Pragmatic Programmers' book about Ruby on Rails, and how much it costs. Because I'm looking for a particular item, I should use the ItemLookup operation. But this means that I need to know the ISBN, which I find is 097669400X. (ECS expects the ISBN without any hyphens or other punctuation.) Finally, I have to get a value for AccessKeyId, an ID number that tells Amazon which developer is accessing the system. (Getting an AccessKeyId is free and easy; see the the on-line Resources for details.)
The base URL for ECS REST requests is http://webservices.amazon.com/onca/xml?Service=AWSECommerceService.
To indicate the operation, AccessKeyId and ItemId, we add name-value pairs onto the URL, using the name=value format and separating the pairs with ampersands (&). Our combined URL thus looks like this: http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&Operation=ItemLookup&AWSAccessKeyId=XXX&ItemId=0735619530.
If you put the above into a Web browser (replacing the XXX with an actual AccessKeyId value), you should see the XML document (with a content-type of text/xml) returned from Amazon's server. That document begins with an ItemLookupResponse tag and is then divided into two sections, OperationRequest (which describes the request that you made, including your browser's UserAgent header and all of the arguments you passed to the service) and Items (which contains the responses from Amazon).
For example, here is the response that I received from my request to Amazon:
<ItemLookupResponse> <OperationRequest> <HTTPHeaders> <Header Name="UserAgent" Value="Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8) Gecko/20051111 Firefox/1.5"/> </HTTPHeaders> <RequestId>1NBTWT1FHDEHJK2G16CT</RequestId> <Arguments> <Argument Name="Operation" Value="ItemLookup"/> <Argument Name="Service" Value="AWSECommerceService"/> <Argument Name="AWSAccessKeyId" Value="XXX"/> <Argument Name="ItemId" Value="097669400X"/> </Arguments> <RequestProcessingTime>0.00745105743408203</RequestProcessingTime> </OperationRequest> <Items> <Request> <IsValid>True</IsValid> <ItemLookupRequest> <ItemId>097669400X</ItemId> </ItemLookupRequest> </Request> <Item> <ASIN>097669400X</ASIN> <DetailPageURL> http://www.amazon.com/exec/obidos/redirect?tag= ↪ws%26link_code=xm2%26camp=2025%26creative= ↪165953%26path=http://www.amazon.com/gp/ ↪redirect.html%253fASIN=097669400X%2526tag= ↪ws%2526lcode=xm2%2526cID=2025%2526ccmID= ↪165953%2526location=/o/ASIN/ ↪097669400X%25253FSubscriptionId=XXX </DetailPageURL> <ItemAttributes> <Author>Dave Thomas</Author> <Author>David Hansson</Author> <Author>Leon Breedt</Author> <Author>Mike Clark</Author> <Author>Thomas Fuchs</Author> <Author>Andrea Schwarz</Author> <ProductGroup>Book</ProductGroup> <Title> Agile Web Development with Rails (The Facets of Ruby Series) </Title> </ItemAttributes> </Item> </Items> </ItemLookupResponse>
There are several particularly useful fields in the previous XML. You can see how much time it took for Amazon to process our request (0.008 seconds, in this case), which might be useful if we need to debug and/or benchmark our application. The DetailPageURL contains the URL to which we can refer users who want to see information about this product on the Amazon site. And, we get information such as the title and author(s), which might be useful when displaying book information.
And indeed, it should be easy to see how we can parse this XML, displaying parts or all of it in a Web, GUI or console application. Or, we can add some part of this data to a larger database application that we are creating, making sure not to violate Amazon's restrictions on the use of retrieved data.
Practical books for the most technical people on the planet. Newly available books include:
- Agile Product Development by Ted Schmidt
- Improve Business Processes with an Enterprise Job Scheduler by Mike Diehl
- Finding Your Way: Mapping Your Network to Improve Manageability by Bill Childers
- DIY Commerce Site by Reven Lerner
Plus many more.