Lyricwiki

Access to Lyricwiki.org’s REST API with pure JavaScript

My objective of today was to get rid of these ugly warnings issued by IE while accessing lyricwiki.org’s REST API using a small Flash thingy. This SWF file is needed to circumvent JavaScript’s cross domain limitation. This security feature avoids that JavaScript from host A loads files from host B. This absolutely makes sense, just imagine how a client connected to the internet and a company’s intranet could be used to steal confidential data. However, this limitation does not apply to JavaScript files loaded with the script tag. Therefore, I suggested to add a JavaScript format to the REST API in order to dynamically access the API using a technique called “On-Demand JavaScript“.

First, I wanted to make the API extension output JavaScript code. However, I found out – know this i probably the right moment to admit that I am not a JavaScript guru ;) – that JSON files can be included by the script tag as well, which makes them suitable for On-Demand JavaScript as well. However, both formats are implemented (JSON used by default) and transparently interchangeable.

The result of my work are 4 files (download), hosted on my company’s website:

(Code is tested with IE6, IE7, FF3 – download now! ;) – and FF2, Public Domain Dedication)

EDIT: updated files to optionally use JSONP. (see comments) I did not use the proposed json_encode() method, as it’s only available with PHP versions >= 5.2.0.

EDIT2: Yay! My proposal finally made its way into production. I therefore changed the files to use the production API instead of my little test script. Additionally, we already moved from the pure txt to the json format on Songtexte.com. This is really cool, as we got rid of this little flash thingy that caused warnings in IE.

EDIT3: Forgot to mention that JSONP wasn’t implemented. However, I’m supposed to get access to Lyricwiki’s API source repository real soon. I will definetely try to implement the optional callback parameter.