- What Is a Web Service?
- Conversational Machines
- Amazon Web Services: REST Versus SOAP
- Programming with REST
- Working with SOAP
- The ZwiftBooks Challenge
- Summary
- References
Amazon Web Services: REST Versus SOAP
AWS comes in two web service delivery flavors:
- SOAP (which originally stood for Simple Object Access Protocol) is a protocol that involves XML data exchange between client and server.
- Representational State Transfer (REST) is a newer, simpler approach to web services. REST assumes HTTP as the underlying transport and most commonly returns only XML to the client.
Let’s begin with REST, because it’s the simpler of the two protocols to understand.
To communicate with AWS by using REST, issue a simple URL query. A URL query looks like a typical URL request, except that it uses a question mark (?) to separate the URL from the query portion and an ampersand (&) to delimit parameters. For example, to send data (let’s say name=bob and age=25) to the server http://www.foobar.com, you would use the following URL:
http://www.foobar.com?name=bob&age=25
Since the server expects a URL query, it’s possible to invoke AWS directly from a web browser, which is great for experimentation and testing. AWS returns XML with elements describing result details.
To illustrate that point, let’s find out what Amazon.com knows about some specific book. All we need is the ISBN, and Amazon.com will tell us everything it knows about the book, including name, title, price, and more. To test the service, enter the following query as a single string, replacing xxxxxxxxxx with your personal Amazon.com key:
http://xml.amazon.com/onca/xml3? t=AssociatesIDwebservices-20& dev-t=xxxxxxxxxx& AsinSearch=0201776413& mode=books& type=heavy &page=1& f=xml
What you get in return is an XML document complete with element names that describe what Amazon.com knows about this book. Listing 1 shows only part of the output that was returned from my query.
Listing 1 Partial XML output from the Amazon.com book search web service.
<ProductInfo xsi:noNamespaceSchemaLocation="http://xml.amazon.com/schemas3/dev-heavy.xsd"> ... <Asin>0201776413</Asin> <ProductName>XML, Web Services, and the Data Revolution (Addison-Wesley Information Technology Series) </ProductName> <Catalog>Book</Catalog> <Authors> <Author>Frank P. Coyle</Author> </Authors> <ReleaseDate>05 March, 2002</ReleaseDate> <Manufacturer>Addison-Wesley Professional</Manufacturer> <ImageUrlSmall> http://images.amazon.com/images/P/0201776413.01.THUMBZZZ.jpg </ImageUrlSmall> ... <ListPrice>$39.99</ListPrice> <OurPrice>$29.13</OurPrice> ... <Isbn>0201776413</Isbn> <Availability>Usually ships in 24 hours</Availability> ... <SimilarProducts> <Product>0596004206</Product> <Product>1578200733</Product> <Product>0764526413</Product> <Product>0672326140</Product> <Product>0596000537</Product> </SimilarProducts> </Details> </ProductInfo>
Looking at the ease with which the service can be accessed, it’s easy to see why REST has been generating a lot of excitement in the web services world. Its selling point is that it’s simple for both humans and computers.
Now that we’ve entered a REST query manually, let’s look at how to do it programmatically.