MooFm: data at your fingertips

March 2, 2009  |  , ,

I came accross some very neat stats visualizations some times ago, and wanted to try out some ideas in JavaScript (probably with Processing.js). I couldn’t find any efficient way to use their API from JS, so I made MooFm…

What is it?

MooFm is a little (<5Ko) MooTools plugin making access to this data as easy as it can be.
It lets you get the stats asynchronously without having to deal with query concatenation or Ajax calls.

How do I use it?

Let’s say we want to get the most popular album of Nirvana. Taking a look at the API guide, we find the documentation for the artist.getTopAlbums method.

// just give MooFm your API key...
var moofm = new MooFm('b25b959554ed76058ac220b7b2e0a026');

var callback = function(resp) {
   // will output "Nevermind"

// methods' name and params are the same as in doc
moofm.artist.getTopAlbums({'artist':'Nirvana'}, callback);

Couldn’t be simpler, right? All readonly methods are accessible this way.

Getting started

To get started you’ll need a recent version of MooTools (obviously), the MooFm.js library and its proxy.
Now get an API key (free), and you’re good to go.

Demo time!

Here is a little demo I put together as an example.


  1. Having some difficulties making this work. It comes back with ‘Class is not defined’ for moofm.js line 1 of code on Tomcat 6.0 run locally. Do You know what might be the problem?
    Appreciate it!

  2. Hi karlis!

    Well this is a MooTools plugin, so you need to include the MooTools Core library in your page. You can get it here:

  3. Perhaps I’m being stupid, but why the need for a server-side proxy? Is this just to deal with XSS concerns?

  4. The proxy is necessary because of the cross-domain restrictions on the browsers: you can’t request a page located on the domain from outside of this domain in JavaScript. The PHP proxy allows you to bypass this restriction (but at the cost of an added latency and more bandwith).

    You can find more info on the subject here.


Leave a Reply