<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Adrian Short &#187; apis</title>
	<atom:link href="http://adrianshort.co.uk/tag/apis/feed/" rel="self" type="application/rss+xml" />
	<link>http://adrianshort.co.uk</link>
	<description>Design, citizenship and the city</description>
	<lastBuildDate>Mon, 07 Nov 2011 09:17:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Hillingdon Council creates an RSS feed for every page</title>
		<link>http://adrianshort.co.uk/2009/04/28/hillingdon-council-creates-an-rss-feed-for-every-page/</link>
		<comments>http://adrianshort.co.uk/2009/04/28/hillingdon-council-creates-an-rss-feed-for-every-page/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 16:04:03 +0000</pubDate>
		<dc:creator>Adrian Short</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Mash the State]]></category>
		<category><![CDATA[apis]]></category>
		<category><![CDATA[feeds]]></category>
		<category><![CDATA[Hillingdon]]></category>
		<category><![CDATA[Hillingdon Council]]></category>
		<category><![CDATA[rss]]></category>

		<guid isPermaLink="false">http://mashthestate.wordpress.com/?p=45</guid>
		<description><![CDATA[Ever wanted to track the changes to a webpage but found there was no easy way of doing it? The Hillingdon Council website makes this easy by generating an RSS feed for every page. At the bottom of each page there&#8217;s a &#8220;Subscribe to this page&#8221; link and feed icon. The site also makes these [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-46" title="hillingdon-subscribe-to-page" src="http://adrianshort.co.uk/wp-content/uploads/2009/04/hillingdon-subscribe-to-page.png" alt="hillingdon-subscribe-to-page" width="400" height="122" /><br />
Ever wanted to track the changes to a webpage but found there was no easy way of doing it? The <a href="http://www.hillingdon.gov.uk/">Hillingdon Council website</a> makes this easy by generating an RSS feed for every page.</p>
<p>At the bottom of each page there&#8217;s a &#8220;Subscribe to this page&#8221; link and feed icon. The site also makes these feeds easy to find by putting them in <a href="http://www.mashthestate.org.uk/faq#autodiscovery">autodiscovery tags</a>, providing a consistent way to subscribe in each browser.</p>
<p>Using RSS as a mechanism for receiving page status updates makes much more sense than writing a custom subscription system and requiring user registration such as on <a href="http://www.sutton.gov.uk/">Sutton Council&#8217;s website</a>.</p>
<p>There&#8217;s plenty of scope for Hillingdon to produce more comprehensive specific feeds for other uses but this is a very useful feature in its own right. Combined with a feed-to-email link on every page to a service like <a href="http://www.feedmyinbox.com/">Feed My Inbox</a> it could see a lot of usage.</p>
<p>Let&#8217;s also remember that there&#8217;s more to life than RSS. Other feed formats and APIs are more appropriate for different types of data such as <a href="http://en.wikipedia.org/wiki/ICalendar">iCalendar</a> for events.</p>
]]></content:encoded>
			<wfw:commentRss>http://adrianshort.co.uk/2009/04/28/hillingdon-council-creates-an-rss-feed-for-every-page/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DDAM: Don&#8217;t discriminate against machines</title>
		<link>http://adrianshort.co.uk/2009/03/30/ddam-dont-discriminate-against-machines/</link>
		<comments>http://adrianshort.co.uk/2009/03/30/ddam-dont-discriminate-against-machines/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 10:06:14 +0000</pubDate>
		<dc:creator>Adrian Short</dc:creator>
				<category><![CDATA[Web design]]></category>
		<category><![CDATA[apis]]></category>
		<category><![CDATA[feeds]]></category>
		<category><![CDATA[FixMyStreet]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://adrianshort.co.uk/?p=354</guid>
		<description><![CDATA[I&#8217;d like to emphasise a point that Emma Mulqueeny has alluded to in her seven principles for digital engagement and which I also made in passing in my previous article on building local news mashups. The web is rife with discrimination of the most insidious and socially-destructive kind. It largely goes unnoticed as those that [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d like to emphasise a point that Emma Mulqueeny has alluded to in her <a href="http://mulqueeny.wordpress.com/2009/03/17/seven-principles-for-digital-engagement-help-me-please/">seven principles for digital engagement</a> and which I also made in passing in my previous article on <a href="http://adrianshort.co.uk/2009/03/15/311/">building local news mashups</a>.</p>
<p>The web is rife with discrimination of the most insidious and socially-destructive kind. It largely goes unnoticed as those that are well-served by the web care little for the plight of those that are not.</p>
<p>I&#8217;m talking about the web&#8217;s widespread discrimination against machines.</p>
<p>Conventional thinking about &#8220;websites&#8221; focuses almost wholly on human users. In the best-case scenario, people turn up to a website, find the information they want or do the thing they want to do, then go away again. If the website is useful and provides that information or service, and if it&#8217;s <a title="Wikipedia: Usability" href="http://en.wikipedia.org/wiki/Usability">usable</a> and <a title="Wikipedia: Web accessibility" href="http://en.wikipedia.org/wiki/Web_accessibility">accessible</a>, people can do what they want to do with a minimum of fuss and effort and be satisfied.</p>
<p>Many websites are a long, long way from being able to provide a good experience for human users but I doubt many don&#8217;t have it as their goal, however ineptly they may deliver on the details.</p>
<p>By contrast, providing for machine users mostly happens either as an afterthought or not at all.</p>
<p>Machine users are other programs, websites or software systems that could interact with your website by extracting data, inputting data, or both.</p>
<p>The simplest example is an RSS feed fetching a list of news articles or job vacancies. By providing an RSS feed, a website makes it easy for other programs to capture that information and re-use it in any way possible. They might republish that information largely as-is, combine it with information from other sources in a <a title="Adrian Short: Building a local news mashup" href="http://adrianshort.co.uk/2009/03/15/311/">mashup</a> or even derive statistical information from it. Or all of these things.</p>
<p>More generally an API allows information to be read from or posted into another system. Can humans search your website? Then provide a search API for machines. Can people place orders and make payments online? Then provide an ordering and payment API. Every form on your website should have an API that makes provision for machine users to post in data and get a machine-readable response. Every sequential collection of information should be available as a feed.</p>
<p>Providing for machine users by building APIs and serving feeds is ultimately about serving human needs. Until machines achieve some kind of consciousness they will neither know nor care about accessing information on other systems. Every program is written by and provides information for people.</p>
<p>APIs make it possible for people to write programs to use your information and services in ways that suit them, in ways that you can&#8217;t anticipate, in ways that you don&#8217;t have the resources to provide, through systems that you won&#8217;t have to maintain. Many organisations won&#8217;t like this. It means the creation of infinite new layers of intermediaries, third-party services that provide new interfaces to your information and services or whole new applications that combine your services with others&#8217;. If you think you can provide the best interface to your services for every conceivable context you&#8217;re a fool. If you think you should be the sole gatekeeper of your services then prepare to lose your customers to other businesses or see your citizens disappear to third-party services implemented through any means necessary.</p>
<p>Let&#8217;s snap out of abstractions for a moment and look at an example.</p>
<p>As an activist with <a href="http://www.livingstreets.org.uk/">Living Streets</a> I&#8217;m always on the lookout for maintenance issues and faults on the street, particularly where they affect pedestrians. I can report street faults directly to <a title="Sutton Council street fault reporting" href="http://eforms.yourlondon.gov.uk/pub/servlet/ep.blank?auth=1902&amp;x=526153&amp;y=163748&amp;zm=12&amp;ut=x&amp;st=sutton&amp;type=streets&amp;method=&amp;prefix=">my local council</a> or I can use <a href="http://www.fixmystreet.com/">FixMyStreet</a>, a national service that <em>ostensibly </em>does the same thing.</p>
<p>I always use FixMyStreet. Why?</p>
<ul>
<li>It&#8217;s easier. The user interface is better.</li>
<li>It&#8217;s geographically agnostic. I can report a fault anywhere in the country without having to know which authority is responsible for it.</li>
<li>It&#8217;s public. There&#8217;s a lot of value for me in being able to see other people&#8217;s street reports as I&#8217;m interested in looking at the wider issue of urban design and maintenance, not just getting a specific fault that bothers me fixed. I can browse other fault reports and see statistics for each borough.</li>
<li>It&#8217;s flexible. I can get reports sent to me by email or through an RSS feed. I can file a report on an <a title="FixMyStreet on the iPhone" href="http://www.mysociety.org/2008/12/10/fixmystreet-iphone/">iPhone</a> and soon through many other mobile clients.</li>
</ul>
<p>Overall it&#8217;s just better, and better in so many ways that my council and most other councils will not be able to emulate.</p>
<p>Smart councils would realise this and most probably abandon their local street fault reporting systems. They could put their resources into developing a clean API between their own faults database and FixMyStreet (or any other similar application). They could actually invest in FixMyStreet itself. It&#8217;s open source, so why not? It&#8217;s not going to disappear, and if it gets superseded by another, better, open-source system, no-one loses.</p>
<p>It&#8217;s APIs (and often, ersatz, hacky APIs) that make this kind of thing possible. It leads to better services, greater participation, and more flexibility, diversity. We need to put machine users on parity with human users so that people can be best served.</p>
<p>If you&#8217;re building any kind of website or online service, serve a feed for every stream and an API for every form. Let this be your mantra: DDAM, DDAM, DDAM. Don&#8217;t discriminate against machines.</p>
<p><em>Like this? <a href="http://twitter.com/adrianshort">Follow me on Twitter</a> or <a href="http://adrianshort.co.uk/feed/">subscribe to my RSS feed</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://adrianshort.co.uk/2009/03/30/ddam-dont-discriminate-against-machines/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Building a local news mashup with Twitter, TwitterFeed, Delicious, Yahoo! Pipes, Ruby and RSS</title>
		<link>http://adrianshort.co.uk/2009/03/15/building-a-local-news-mashup-with-twitter-twitterfeed-delicious-yahoo-pipes-ruby-and-rss/</link>
		<comments>http://adrianshort.co.uk/2009/03/15/building-a-local-news-mashup-with-twitter-twitterfeed-delicious-yahoo-pipes-ruby-and-rss/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 18:35:27 +0000</pubDate>
		<dc:creator>Adrian Short</dc:creator>
				<category><![CDATA[Software design]]></category>
		<category><![CDATA[Sutton]]></category>
		<category><![CDATA[apis]]></category>
		<category><![CDATA[atom]]></category>
		<category><![CDATA[Delicious]]></category>
		<category><![CDATA[Hpricot]]></category>
		<category><![CDATA[mashups]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[Paul Burstow]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Stonecot Hill News]]></category>
		<category><![CDATA[Sutton Council]]></category>
		<category><![CDATA[Sutton Guardian]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[TwitterFeed]]></category>
		<category><![CDATA[Yahoo! Pipes]]></category>

		<guid isPermaLink="false">http://adrianshort.co.uk/?p=311</guid>
		<description><![CDATA[(Click on the image to download the PDF, 19KB, opens in new window/tab.) Like this? Follow me on Twitter: http://twitter.com/adrianshort I&#8217;m a self-confessed and unashamed news junkie and this is how I&#8217;m starting to mash up news in my local area. For those that aren&#8217;t local, Sutton is a London borough with a population of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://adrianshort.co.uk/wp-content/uploads/2009/03/sutton-local-news-mashup.pdf" target="_blank"><img class="alignnone size-medium wp-image-330" title="sutton-local-news-mashup" src="http://adrianshort.co.uk/wp-content/uploads/2009/03/sutton-local-news-mashup-400x282.png" alt="sutton-local-news-mashup" width="400" height="282" /></a></p>
<p><em>(Click on the image to download the PDF, 19KB, opens in new window/tab.)</em></p>
<p><em>Like this? Follow me on Twitter: <a href="http://twitter.com/adrianshort">http://twitter.com/adrianshort</a><br />
</em></p>
<p>I&#8217;m a self-confessed and unashamed news junkie and this is how I&#8217;m starting to mash up news in my local area. For those that aren&#8217;t local, <a href="http://en.wikipedia.org/wiki/London_Borough_of_Sutton">Sutton</a> is a London borough with a population of approximately 180,000. Stonecot Hill is a neighbourhood within Sutton with a population of a few thousand.</p>
<p>Here&#8217;s how it all works.</p>
<p><strong>Sources (green boxes)</strong></p>
<p>I write <a href="http://www.stonecothillnews.co.uk/">Stonecot Hill News</a> which is a local news blog running as a standalone <a href="http://wordpress.org/">WordPress</a> installation on its own server. It produces an <a href="http://en.wikipedia.org/wiki/RSS_(file_format)">RSS 2.0 feed</a> which here is treated as an outbound <a href="http://en.wikipedia.org/wiki/Api">API</a>.</p>
<p><a href="http://paulburstow.com/">Paul Burstow</a> is the local member of parliament (constituency: Sutton &amp; Cheam). Paul posts news regularly to his website and for many years that site has been serving an RSS 1.0 (RDF) feed. Whether he realises it or not, Paul laid one of the first foundations for news mashability in the borough.</p>
<p>The <a href="http://www.suttonguardian.co.uk/">Sutton Guardian</a> is the local newspaper, published by Newsquest. Together with its sister titles in other areas, they publish <a title="Sutton Guardian RSS feeds" href="http://www.suttonguardian.co.uk/misc/rss/">several dozen RSS 2.0 feeds</a> for a wide variety of content.</p>
<p><a href="http://www.sutton.gov.uk/">Sutton Council</a> is the local authority for the borough. Despite a recent £270,000 revamp to their website they haven&#8217;t yet managed to step into the Twenty-First and produce any RSS feeds. However, they do publish a variety of content regularly on their website, including their <a title="Sutton Council press releases" href="http://www.sutton.gov.uk/index.aspx?articleid=3434">press releases</a>.</p>
<p><strong>APIs (grey boxes)</strong></p>
<p>For the non-technical: API stands for Application Programming Interface, but that doesn&#8217;t tell you very much. Think of APIs like connectors or adapters that allow one program to plug into another in the same way that our household appliances can all connect to the electrical network because they share common plugs and sockets.</p>
<p>An API may be <em>inbound </em>(allowing data to be put into an application), <em>outbound </em>(allowing data to be extracted) or both.</p>
<p>As we can see in the diagram, applications which use APIs can be daisy-chained together, with the output of one application being fed into another.</p>
<p>RSS and <a href="http://en.wikipedia.org/wiki/Atom_(standard)">Atom</a> feeds are also APIs in that they provide a structured way for a program to get data out of an application. These feed formats are simple to implement (many applications produce them automatically) and are the first thing to consider when implementing a simple outbound API for an application.</p>
<p><strong>Mashers (pink boxes)</strong></p>
<p>Mashers are small programs that connect otherwise incompatible inbound and outbound APIs together. <a href="http://twitterfeed.com/">TwitterFeed</a> is a simple example. Say you want to automatically post the new items from your blog to your <a href="http://twitter.com/">Twitter</a> account. Your blog serves an RSS feed but Twitter, while it has an inbound API, cannot accept RSS directly as input. TwitterFeed links the two, allowing the user to define any number of RSS feeds as inputs and any number of Twitter accounts as outputs, via the Twitter API. In this way, TwitterFeed plugs blogs into Twitter.</p>
<p><a href="http://pipes.yahoo.com/">Yahoo! Pipes</a> is a much more sophisticated and flexible masher. It can take inputs from a variety of sources (RSS, Atom, <a title="Comma-separated values file format" href="http://en.wikipedia.org/wiki/Comma-separated_values">CSV</a>, <a title="Flickr photo sharing website" href="http://www.flickr.com/">Flickr</a> API, <a href="http://base.google.com/base/">Google Base</a> or even raw web pages), sort, filter and combine them in every conceivable way, and output the results as a single stream in various formats (RSS, <a title="JavaScript Object Notation" href="http://en.wikipedia.org/wiki/Json">JSON</a>, and <a title="KML - Keyhole Markup Language" href="http://en.wikipedia.org/wiki/Kml">KML</a>, the geo-format used by <a href="http://earth.google.com/">Google Earth</a>). For my mashup I created <a title="Stonecot Hill news mashup Yahoo Pipe" href="http://pipes.yahoo.com/adrianshort/tin_59X73RG83ZoNpgt1Yg">this pipe</a> to filter Paul Burstow&#8217;s, the Sutton Guardian&#8217;s and Sutton Council&#8217;s news and only pass through items containing the word &#8220;stonecot&#8221; to the stream that eventually ends in the <a href="http://twitter.com/stonecothill">@stonecothill Twitter feed</a>, which is just for Stonecot Hill residents. The number of items coming through these sources about Stonecot Hill is very low, but when something appears residents will want to see it. (By way of example, only a single press release from Sutton Council in the last 227 concerns the Stonecot Hill area specifically.)</p>
<p>As mentioned above, Sutton Council doesn&#8217;t provide an RSS feed or any other kind of outbound API for its press release. I wrote a screen scraper in <a title="Ruby programming language" href="http://www.ruby-lang.org/en/">Ruby</a> (using <a title="Hpricot HTML parser for Ruby" href="http://wiki.github.com/why/hpricot">Hpricot</a>) that grabs the press releases directly from the council website, dumps them into a <a href="http://www.mysql.com/">MySQL</a> database and pushes new items into the <a title="Delicious social bookmarks manager" href="http://delicious.com/">Delicious</a> API. I&#8217;ve used Delicious here for two reasons. Firstly, because it generates an RSS feed automatically from all the items posted to it, so I can easily connect this output to other mashers and APIs further downstream without having to generate and host an RSS feed myself. Also, Delicious provides a useful search facility on its website allowing me to easily search just the press releases from Sutton Council. This isn&#8217;t possible with the council&#8217;s own website, where searches are scoped to the entire site.</p>
<p><strong>Destinations (orange boxes)</strong></p>
<p>In my diagram, the destinations are sites and services which represent new ways of consuming information coming from the original sources. Don&#8217;t want to read Sutton Council&#8217;s press releases on their own website? You can folllow them in <a title="Sutton Council's press releases on Delicious" href="http://delicious.com/suttonboro">Delicious</a> or on <a title="Sutton Council's press releases on Twitter" href="http://twitter.com/suttonboro">Twitter</a>. Want to keep up with the latest news about Stonecot Hill? Again, the <a href="http://twitter.com/stonecothill">@stonecothill Twitter account</a> can find this for you from various sources. I also add my own items to @stonecothill, making it a unique mashup of original and syndicated content that&#8217;s highly targeted and very local.</p>
<p>The information stream doesn&#8217;t need to end with these destinations. Any destination that provides an outbound API can simply be another link in the chain to downstream services. In my diagram, the RSS feed from Delicious is used to do just that, pushing all its content on to the @suttonboro Twitter account, and just the Stonecot Hill-related content on to the @stonecothill account via the Yahoo! Pipes filter. Twitter has its own specific outbound API and also serves RSS feeds. There&#8217;s nothing to stop anyone else building on these destinations by combining and filtering them with other sources to produce their own unique, relevant information streams that they find useful.</p>
<p><strong>What next?</strong></p>
<p>If you run a website, it&#8217;s time to start thinking of mashability with the same degree of seriousness as you treat human visitors. Your website needs to serve up feeds and APIs so that other programs can connect to your content and deliver it to people in ways and contexts that they find useful. Some of these may have an audience of thousands or even millions. Others may have an audience of one. Regardless, by providing an API to your content you enable others to build things that you haven&#8217;t imagined, don&#8217;t have the resources or desire to build yourself, and won&#8217;t have to maintain. Businesses like newspapers that survive by selling their content (or selling advertising around their content) are thinking very carefully about the challenges and opportunities for the future of their industries. For government and voluntary organisations, it&#8217;s time to start thinking more like evangelists than economists. Spread the word like the free Bibles in hotel bedrooms and take every opportunity to get your message out there.</p>
<p>Sutton Council have been encouraged in various ways to implement feeds on their own website and the song will remain the same until they do. I don&#8217;t want to maintain my scraper for ever and I certainly don&#8217;t want to build any more of them.</p>
<p>The whole API and mashability agenda is far bigger than simple web feed formats like RSS and Atom. It&#8217;s time for technologists to stop flogging the line that &#8220;RSS is an easy way for people who follow lots of websites to read all their news in one place&#8221;. Direct human consumption of RSS feeds is never going to hit the mainstream in that way. If you&#8217;re reading this, you&#8217;re far more likely that average to use an RSS reader. (I&#8217;ve got 86 feeds in my <a href="http://www.google.com/reader/">Google Reader</a> right now). The average web user has barely heard of the concept and most definitely don&#8217;t do it. I suspect they never will. But it&#8217;s likely they&#8217;re already benefiting from syndicated content through sites and applications that they use. If they never have to see or care about the underlying technology that&#8217;s really no more a problem than worrying that the average web user doesn&#8217;t understand <a href="http://en.wikipedia.org/wiki/Http">HTTP</a> or <a href="http://en.wikipedia.org/wiki/Domain_Name_System">DNS</a>. It&#8217;s just plumbing that can stay out of sight and out of mind as long as it works.</p>
<p>For the minority that do use personal RSS readers, I&#8217;d like to see more of them with built-in filtering features. Setting a simple keyword filter on a feed makes RSS reading considerably more powerful.</p>
<p>For those serving up feeds, I&#8217;d like to see Atom more widely used. Without wanting to open a can of Wineresque worms, RSS 2.0 fudges a number of important issues around content semantics and provides no support whatsoever for correctly attributing items in feeds mashed from several sources. Atom was designed to solve these problems and it does. Let&#8217;s use it.</p>
<p>Lastly, mashability is about every conceivable kind of content and content type. It&#8217;s not just about news and text. Every stream of information should have its own machine-readable feed. Every system that can accept data from human input should implement an inbound API to do likewise. To take one example, <a href="http://www.fixmystreet.com/">FixMyStreet</a> is a website for people to report street faults to local authorities and currently takes around 1000 reports a week. It even has its own <a title="FixMyStreet on the iPhone" href="http://www.mysociety.org/2008/12/10/fixmystreet-iphone/">iPhone application</a> so people can report faults complete with GPS locations and photos directly from the street. Only a single local authority in over 400 has implemented an inbound API to receive these reports. The rest get them by email, which must be manually copied into their own databases with all the effort, expense, possibility for error and opportunity costs that represents. Third-parties building extensions to other people&#8217;s systems is no longer unusual, so organisations need to embrace the possibilities rather than fighting against it or standing around looking bemused.</p>
<p>It&#8217;s time to open the doors and windows and get the web joined up, mashed up and moving.</p>
]]></content:encoded>
			<wfw:commentRss>http://adrianshort.co.uk/2009/03/15/building-a-local-news-mashup-with-twitter-twitterfeed-delicious-yahoo-pipes-ruby-and-rss/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>My thermometer has got an API</title>
		<link>http://adrianshort.co.uk/2009/03/02/my-thermometer-has-got-an-api/</link>
		<comments>http://adrianshort.co.uk/2009/03/02/my-thermometer-has-got-an-api/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 20:06:29 +0000</pubDate>
		<dc:creator>Adrian Short</dc:creator>
				<category><![CDATA[Software design]]></category>
		<category><![CDATA[apis]]></category>
		<category><![CDATA[everyware]]></category>
		<category><![CDATA[Internet of Things]]></category>
		<category><![CDATA[sensors]]></category>
		<category><![CDATA[thermometers]]></category>
		<category><![CDATA[ubicomp]]></category>
		<category><![CDATA[ubiquitous computing]]></category>

		<guid isPermaLink="false">http://adrianshort.co.uk/?p=275</guid>
		<description><![CDATA[Meet my thermometer. It&#8217;s an old-school analogue device, probably at least 50 years old. I don&#8217;t expect it&#8217;s very accurate, certainly not by scientific standards. It hangs outside my door and every now and then I take a look at it and record its reading. But this is no ordinary thermometer. It&#8217;s eqiupped with a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://adrianshort.co.uk/wp-content/uploads/2009/03/thermometer-800.jpg"><img class="alignnone size-medium wp-image-276" title="Stonecot Hill thermometer" src="http://adrianshort.co.uk/wp-content/uploads/2009/03/thermometer-800-268x400.jpg" alt="Stonecot Hill thermometer" width="268" height="400" /></a></p>
<p>Meet my thermometer.</p>
<p>It&#8217;s an old-school analogue device, probably at least 50 years old. I don&#8217;t expect it&#8217;s very accurate, certainly not by scientific standards. It hangs outside my door and every now and then I take a look at it and record its reading.</p>
<p>But this is no ordinary thermometer. It&#8217;s eqiupped with a capability that would have probably been inconceivable to the people that made it: it has its own <a title="Wikipedia: Application Programming Interface" href="http://en.wikipedia.org/wiki/API">API</a> so that programs can &#8220;read&#8221; it, automatically, across the Internet.</p>
<p>Before explaining <em>how </em>you can use the API I should explain <em>why </em>I&#8217;ve bothered to do this.</p>
<p>By any sensible standard, this project in itself is almost completely useless. I haven&#8217;t created any kind of clever link between the thermometer and the database in which I store its readings. I just read it when I feel like it. Some days I might get five or six readings. (You can get more sophsiticated computer-connected thermometers that do this automatically but I don&#8217;t have one.) Then I might go for five or six days without reading it at all. Combined with what I assume is a fairly low level of accuracy as a result of the device itself, its positioning and the possibility of human error when reading it and recording its value, the data produced seems almost worthless.</p>
<p>There is a crucial difference between <em>almost </em>and <em>completely </em>worthless.</p>
<p>This project is my first contribution towards the <a href="http://en.wikipedia.org/wiki/Internet_of_Things">Internet of Things</a>. The thermometer is a very simple sensor, producing, as I&#8217;ve explained, very low quality data. The API is incredibly basic. There is only one query: read the thermometer. And the result is the following hash:</p>
<table border="1" cellpadding="10">
<tbody>
<tr>
<td>temperature_c</td>
<td>Latest (not current) temperature, in centigrade</td>
</tr>
<tr>
<td>ts</td>
<td>Unix timestamp of the latest reading</td>
</tr>
<tr>
<td>lat</td>
<td>Approximate latitude of the thermometer</td>
</tr>
<tr>
<td>lng</td>
<td>Approximate longitude of the thermometer</td>
</tr>
</tbody>
</table>
<p> </p>
<p>This thermometer is a very simple device with a very basic interface. If you&#8217;re relying on it to provide up-to-date, accurate temperature data, you&#8217;re a fool. But imagine if a dozen people in my neighbourhood did exactly the same thing &#8212; all reading their not-particularly-accurate thermometers whenever they felt like it and updating their databases. As the number of thermometers increases the chance of being able to find a sufficiently-recent reading from one of them improves. And as the data from all these thermometers is being read by a program (or programs), it&#8217;s quite possible to use statistical techniques to smooth out any apparent errors.</p>
<p>This is the opportunity afforded by the <a href="http://en.wikipedia.org/wiki/Internet_of_Things">Internet of Things</a> (sometimes known more generally as <a href="http://en.wikipedia.org/wiki/Ubiquitous_computing">ubiquitous computing</a> or <a title="Everyware: the dawning age of ubiquitous computing by Adam Greenfield" href="http://books.google.co.uk/books?id=noMNgMcZvL0C&amp;dq=everyware&amp;printsec=frontcover&amp;source=bn&amp;hl=en&amp;ei=vzmsSaq1BJDDjAeNhK3UDw&amp;sa=X&amp;oi=book_result&amp;resnum=4&amp;ct=result">everyware</a>). The model is almost completely opposite to current ideas in server and desktop computing, which are focused on a relatively small number of devices with ever-increasing computing power, storage capacity and sophistication. IoT takes a very large number of fairly stupid devices that have, as a minimum, the ability to network with other things and serve up just one piece of useful information, and then mashes them up into something that&#8217;s infinitely more powerful than the sum of its parts.</p>
<p>Imagine a world in which most objects know who they are, where they are and can serve up very basic reports on their status to other objects. Such a &#8220;system&#8221; would be massively redundant. Like the cells in a body, no one object would be necessarily particularly important in the grand scheme of things. It&#8217;s the power of being able to combine these things together &#8212; and of them being able to combine themselves &#8212; that opens up a wealth of new directions. A city in which every lamppost could transmit its precise location would likely be more accurate than GPS. Lampposts don&#8217;t move and they don&#8217;t get obscured by clouds.</p>
<p>Making this happen won&#8217;t require any fundamentally new technological advances, just small improvements to the cost of existing ones. Platforms like <a href="http://www.pachube.com/">Pachube</a> already exist to enable people to network these kinds of devices and build complex, emergent systems on top of them.</p>
<p>Grand schemes aside, using the thermometer&#8217;s API is very simple. Just send an HTTP GET request to:</p>
<p>http://www.stonecothillnews.co.uk/thermometer.php</p>
<p>and you&#8217;ll get back a JSON-encoded hash as described above. This is the <em>latest </em>reading that has been taken on the thermometer. It could have been a minute or a month ago.</p>
<p>Here&#8217;s how you do it in PHP:</p>
<p><code>&lt;?php<br />
define('ENDPOINT', 'http://www.stonecothillnews.co.uk/thermometer.php');<br />
$handle = fopen(ENDPOINT, 'r');<br />
$contents = fread($handle, 8192);<br />
fclose($handle);<br />
$data = json_decode($contents);<br />
print_r($data);<br />
?&gt;<br />
</code></p>
<p>and here&#8217;s a Ruby example:</p>
<p><code><br />
require 'open-uri'      # URI wrapper for File.open<br />
require 'activesupport' # for JSON decoding<br />
require 'pp'            # pretty printer</p>
<p>ENDPOINT = 'http://www.stonecothillnews.co.uk/thermometer.php'</p>
<p>handle = open(ENDPOINT)<br />
output = handle.read<br />
handle.close<br />
data = ActiveSupport::JSON.decode(output)<br />
pp data<br />
</code></p>
<p>I don&#8217;t imagine many readers will have a great deal of use for irregularly-updated temperature data from my neighbourhood. But imagine what could be possible with the contributions of millions of devices like this.</p>
]]></content:encoded>
			<wfw:commentRss>http://adrianshort.co.uk/2009/03/02/my-thermometer-has-got-an-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
