JSON and Callback

Project NemDigitaliser

When looking at one of Digitaliser.dk’s demonstration tools, I discovered some undocumented features of the REST API. First of all, I found out how to get the api to spit out JSON rather than XML (add ?format=json !). I also found out that, with inspiration from Yahoo I suppose, digitaliser.dk has implemented the callback method, which allows machines/users to ‘create’ functions ‘on the fly’, by naming them, e.g. callback=digitaliser. The technically inclined can check the example below:

<script type="text/javascript">
function digitaliser(obj) {
<script type="text/javascript" src="http://api.digitaliser.dk/rest/resources/399475?format=jsonp&callback=digitaliser">

The first script has a simple function: show an alert with the TitleText object from the content called by the second script. Or modified a bit, it grabs any other object. So, what kind of resource is #399475?

Taking this a little step further, I have created a simple Lookup service, where you enter a digitaliser.dk-id and get its resource type back. If you ever see a number and wonder what kind of resource it represents, use my bookmarket (mark the number and click the bookmarklet link). I’ll be the first to admit that this is not very useful as a tool, but the methods and functions are relevant for understanding how to interact with the api. So.