Using Web Service APIs (Amazon and Yahoo!) with PEAR
(Page 1 of 4 )
In this third part to a four-part series that takes you on a tour of the PEAR package, you'll learn how to handle Web Service APIs with PEAR. If you've ever used Web Service APIs before, you'll be pleased at how easy this is. If you've never used one, never fear: we start by briefly explaining what they are and what they let you do. Then we'll take a close look at two: one from Amazon, and one from Yahoo.
About Web Services
Many modern web sites provide an interface to their data and functionality with an API or Web Service. Many of these services are provided over the web, and are often free to use, although many require you to register and obtain an API key, so they can better track how their services are being used. Generally, you can obtain the key immediately online after providing contact information and agreeing to specific terms of service.
Within PEAR (PHP Extension and Application Repository), there are pre-written interfaces to many of these services. These packages act as drop-in modules that make connecting to and using these web services very simple. Without using a pre-written library, you'll find yourself writing code to create requests in various formats, parsing XML or other results, and handling varying authentication and error code systems.
In this article, we'll look at two of theses packages: Services_Amazon and Services_Yahooo. These services allow us to create a storefront and provide search and other analysis capabilities to our end-user. We can provide these capabilities primarily on a site we host, harnessing Amazon and Yahoo! from our PHP code.