///PHP-friendly web services/APIs for quick mashups

PHP-friendly web services/APIs for quick mashups

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.

However, most APIs won’t offer serialized PHP output; some might offer JSON, or JavaScript Object Notation, which is somewhat like PHP’s serialized data (although JSON is integrated in the JavaScript language). Others offer XML gateways, while some even provide SOAP, a (rather complicated) means for computers to talk to each other natively. You really have three options:

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:

Have a look through these APIs and you could be building a mashup quickly in no time.

2008-04-04T00:57:39+00:00 April 4th, 2008|PHP|0 Comments

About the Author:

Leave A Comment