[BSRPE PIC] Chapter 33.   Using Web Service APIs


[ This chapter does not appear in the book. ]

This chapter describes programming techniques for writing standalone programs that employ Web-based service APIs. As a test-bed, I'll implement an application which sends a book title to a service, and gets back a PNG image of the book's cover. I'll write five versions: one each for Google, Amazon, and eBay, and two aimed at Yahoo. There's a high degree of commonality between them, since they all pass through five stages:

  1. A search query is built as a URL.
  2. The query is sent to the server-side where it's processed as a HTTP Get request. In the meantime, the client application waits for an answer.
  3. A response is eventually received back at the client as a string.
  4. The string is parsed into structured data, typically XML or JSON.
  5. Relevant information is extracted from the data structure, often using a path expressions language such as XPath.

These stages are shown in the diagram at the top of this page, which I'll refer to using the mnemonic BSRPE.

There's usually also a step 0 the programmer signs up with the Web service to obtain an application ID, and perhaps a password or secret key. The ID and password are included in the URL created during stage 1.

For more complicated searches, the five stages frequently occur twice. The first time they comprise a search phase where the user supplies a list of criteria in the URL, and the resulting data structure contains possible matches. A lookup phase follows, which also has five stages, where more information is obtained for a particular match.

The service APIs that I employ are:

These services offer multiple language interfaces, including JavaScript, PHP, and Flash, but I'll utilize their Java versions so I can write standalone applications that doesn't require a Web browser.




Dr. Andrew Davison
E-mail: ad@fivedots.coe.psu.ac.th
Back to my home page