I mentioned in the previous post that a
widget is just some code that people can stick on their website. A web-based widget can be directly embedded (such as a Flash or Flex application), or it could simply be an
IFRAME linking to code somewhere else. For this example, I created the file
widget-photo.php and linked to it from an iframe.
The cool part of this example isn't that a page "lives" within another. The magic happens when the user searches for their local congressperson. When a
last name is submitted, the code within the embedded page makes a couple API calls. Using the
SunlightLabs API, the PHP script asks for a list of congresspeople with the given last name. The SunlightLabs
API returns a nicely-formatted
JSON result set. We have officially used an API.
A
mashup is just an easy way of saying that two or more functionalities have been combined in hopes of producing something more interesting / helpful / meaningful / awesome, etc. A pretty solid mashup example is
HousingMaps, which mashes together
craigslist and
Google Maps.
The example isn't over yet. We have just returned data regarding a congressperson or bunch of congresspeople. We're about to display them, but there's something we forgot before making this a
true mashup. For each congressperson, we're also making a call to the
CARMA API to try and find some other information related to that person. We make a call, enter the congressperson's name for the input, and in exchange are given an XML file of that congressperson and their CARMA statistics. How we choose to display all this information is anyone's call from here.
Mission accomplished.
Source:
http://tech.forumone.com/code_examples/widget-photo.phph