About   |   Projects   |   Elsewhere   |   Work   |   Feeds   |   Contact

What’s an API and why do I want one?

[cross-posted from the Headshift blog]

That’s a question I was asked a few days ago by a client.  It’s a fair question, too – there’s no point in building features into systems unless they provide some benefit, so why would you want to spend time and effort doing this?   And for that matter, what exactly IS an API?

The acronym stands for “application programming interface”, which is a typically over-engineered way of saying “means of putting information in and getting information out of your system without having to type it yourself”.   Typically you’ll provide the API with some information, and in return the system will process and spit back some other data.   There’s any number of analogies that you can use, but one of my favourites is the cash machine.   That’s pretty much an API for your bank – you put in your card and enter your PIN, ask the bank for money, and it then dispenses cash.   The information you’re providing is the data on your card and your PIN, while the bank is supplying you with cash and a little paper slip telling you how big your overdraft is.

An “API” for a bank is a good thing if you want to get at your money, but why is it such a big deal for a piece of software?

To start with, very few software systems these days exist in isolation.   If it’s an accounting package, you’ll probably want it to hook up to your bank so you can send and receive payments automatically.  If it’s an ERP system, you’ll find it useful if you could send your purchase orders electronically to your suppliers rather than relying on the steam telephone.   And if you want to tell your customers where your outlets are, you can embed a Google map into your website to plot their locations so that your customers can find you.

All of these are examples of systems using APIs, but it doesn’t stop there.  Increasingly, systems are providing APIs without necessarily having a clear idea of what they’re going to get used for.   In some ways, that’s a violation of my sweeping statement about there being no point building features without having returns – but the point here is that there’s no guarantee that you’re best placed to know *what* those returns might be.

Take Moo, for example.  They print things – stickers, business cards, postcards and so on.   They’ve also got an API.  So what the hell would a printing company do with an API?

The answer is, suprisingly, quite a lot.   Former Headshift colleague Tom Armitage created an application that takes a set of Flickr photographs, calculates their average colours and creates stickers.   They’re very tangible, suprisingly beautiful and almost completely pointless – unless, that is, you’re Moo who make money for every sticker that they print.   Another example is Barcode Sticker-o-Matic that lets you create QR code stickers.   Previously, creating QR codes was a pain, and creating QR code stickers was even more of a pain – but mashing up the two things creates something very much easier and useful.

Another example (and bear with me while I unashamedly pimp some of my own creations) is Twitter.   Their API enables you to create tweets with code, rather than the website.   So I’ve used this to create Twitter bots that tweet the high and low tides of the River Thames; and tweet the values of various stock markets every hour.  The first example is something of a play thing (although as an aside, I actually think you can gain some value to be gained by providing an inanimate object with a “personality”), but the second could conceivably be useful if you needed a peripheral update of how badly the markets were doing.

So much for the entertainment value, but what about the potential business value for providing an API?

There are two things to consider.  The first is that you could potentially make it easier for your customers to deal with you.   If your clients can place orders directly onto your system through your API, that’s going to speed things up.  It’s also going to cut down on errors and duplication, particularly if you can give them information about lead times and stock levels there and then.   And on the assumption that the easier it is to deal with you, the more people will, that should translate through to the bottom line.

The second thing – and to me, the most powerful – is that your customers may want to interact with you in ways that you’d never thought of.   It’s fairly unlikely that Moo realised that they’d end up printing QR codes when they wrote their API, and I’m absolutely sure that Twitter weren’t expecting me to come along and impersonate the River Thames.  And the same probably goes for for huge numbers of other organisations as well.  Imagine if Sainsbury provided an API for their home shopping service.  How long do you think it would be before someone created an iPhone application that allowed you to scan the barcode on the last tin of beans in your cupboard, and automatically add that into your basket, which would then be automatically ordered as soon as the value triggered their free delivery option.  Oh, and interrogated your Google calendar to find the slot when you weren’t planning to be out for evening?   I don’t work for Sainsburys – and they’ve certainly never tried to ask me about what I want from them – but if they provided an API for me to play with, then I’d definitely be having a go at it.

I’m going to make a wild prediction that no corporate software system will ship WITHOUT an API in three years time, and that organisations that can’t provide an interface for their customers are going to find that an increasingly difficult omission to justify.  So the question is not so much, “what’s an API and why do I want one”, as “what’s my API going to do and when can I have it”…

3 June 2009

Work

1 comment

links for 2009-05-28

29 May 2009

Links

No comments yet

links for 2009-05-26

27 May 2009

Links

No comments yet

links for 2009-05-24

25 May 2009

Links

No comments yet

Howduino and panda hacking

3556669644_7e72ed13e0.jpg
I spent yesterday in Liverpool at Howduino – billed as a “one day event about connecting the internet to the real world, breathing life into inanimate objects and creating new ways to interact with things”, it took place at FACT (somewhere that’s worthy of a blog post in itself).

Imagine a room full of geeks, artists and hackers who’d been let loose with soldering irons and toys, and then throw in the capabilities of Arduino boards. The end results ranged from painting with bristlebots through to circuit-bent Furbies.

I took my panda along, together with a box of analogue meters. Ebay is a fantastic source of that kind of retro kit, and I’ve picked up several moving-needle meters from the late 50s for less than a tenner each. The main plan, though, was to fit an old aircraft fuel-flow meter into the panda so he could display trends and changes in an easier-to-visualise way than the LEDs.

The meter itself is just a basic voltmeter with a dial calibrated from 0 to 800 lbs per hour – presumably it came out of some kind of jet, although I’m not sure how big an engine that would imply. There’s an XLR-style bayonet connection on the back, but I drilled two holes into the back of the case and soldered flyleads onto the internal terminals to make things easier. Then the panda got hacked open, and the meter was hot-glued into the wound.

Actually getting it to work was a bit of a challenge, however. The first problem is that the meter is *incredibly* sensitive – full-scale deflection takes less than 0.5 volts. The Arduino’s analogue outputs range from 0 to 5V, so I had to connect the Arduino output to a voltage divider (having first tried to figure out the right resistor values with a rotary potentiometer.) The PWM output from the Arduino runs from 0 (off) to 1023 (full on) with the duty cycle ranging roughly linearly between the two, so it’s just a case of adjusting the deflection to full-scale at 1023, and the rest falls into place.

The biggest problem, though, was with the Arduino itself. I’ve got a Ethernet shield which fits on top of the main board, and had that linked to an old ADSL router with a 4-port hub. Getting to the outside world took longer than I could be bothered with tinkering, so I ended up running a server locally on my Mac with MAMP to give the Arduino something to talk to.

Getting it talking needs the Ethernet library, and that’s buggy. It would connect fine the first time, but then crashed immediately you tried to establish a second connection. Adrian McEwan (who organised the whole thing) pointed me in the direction of a patched version, but I didn’t R the FM closely enough and only installed the library file. You actually have to remove the (old) compiled version as well – once I’d figured that out, the code started to function as it was supposed to.

The Arduino sketch establishes a connection to a server and grabs an XML file using the Ethernet methods. That then gets parsed using the unfeasibly low-tech string library and finally converts the XML value into a PWM value which controls the duty cycle of the analogue output. Because of the inertia of the needle, the pulses are smoothed out and the display reads steady.

The XML file could come from virtually anywhere – Pachube for example – but I’ve got a few Ruby scripts running on one of my servers that does some manipulation before creating the final values as XML. The challenge now is going to be the data source – and ideally something with a range from 0 to 800, and units of pounds per hour. Any suggestions?

24 May 2009

Play

No comments yet

links for 2009-05-23

24 May 2009

Links

No comments yet

links for 2009-05-22

23 May 2009

Links

No comments yet