If you want to build a useful app quickly, you can’t go past a mashup. Take data from someone else’s service, come up with a useful way to mix it up and present it to your users in an innovative manner. Even better, as my recent PHP Site Search tutorial showed, you can build a mashup in just a few lines of code. But how do you find useful web services/APIs, and how do you process the data they provide?
Finding APIs/web services
Finding APIs and web services is really quite easy. If you regularly use a web application – for example, I’ve often used Twitter – check if the application provides an API (Twitter has quite a comprehensive one). Next, if you’re looking for data on a particular topic, try searching for it. A quick search for “map api” returns all kinds of useful results. Finally, if you just want to take a look at the internet’s available APIs, head to Programmable Web; they have by far the most comprehensive database available, and it’s fully searchable.
Handling API output
The easiest way is a really PHP-friendly APIs that provides serialized PHP. You can just fetch the URL with file_get_contents(), and run the output through unserialize(); in two lines of code, you have your data ready to work with.
1. Interpret the output of the API or web service with a PHP-based parser, such as an XML parser (which you can easily find on phpclasses.org) or a SOAP client (try nusoap).
2. Use PHP sample code provided by the API/web service owner – e.g. this Google Checkout PHP sample. Some even provide PECl extensions.
3. Use a third-party library to access the service. For example, people have written PHP classes that allow you to interact with the Flickr API. PHP Classes.org has hundreds of these, and others are just a web search away.
Some PHP-friendly APIs
Of course, if you just want to get started right now and quickly add some functionality to your application, try these:
- reCAPTCHA PHP library: add effective CAPTCHA to your application in pure PHP with reCAPTCHA
- Yahoo PHP developer center: Yahoo! provides some very useful search APIs that you can probably use. Also see my PHP Site Search Made Easy tutorial making use of these APIs.
- Flickr Services with PHP Response
Have a look through these APIs and you could be building a mashup quickly in no time.