trove-js

trove-js is a JavaScript library to access the National Library of Australia's (NLA) Trove v2 API.

The Trove website can be found at: https://trove.nla.gov.au

Trove's v2 API is documented at: http://help.nla.gov.au/trove/building-with-trove/api-version-2-technical-guide

This library works with: https://api.trove.nla.gov.au/v2

A Simple Search Example

First, we need to initialise the library with your key. This key will be passed along with every query to the Trove servers and is a required parameter.

Trove.init(your_key);

You can do that here:

Now, let's search the newspaper zone. First we create a Search object. The zones we search can be specified on construction, as we do here, or passed with each call to the query() method. The same is true for the done callback.

var newspaper_search = new Trove.Search({
    zones: [Trove.ZONES.NEWSPAPER],
    done: newspaper_search_done
});

Then we call the query() method on the search object. Again, we can specify search terms on construction, but it makes sense here to specify them every time you call query() so that we can update them with the current value in the text input (known here as 'trovesearch').

newspaper_search.query({
    terms: trovesearch.val(),
    number: 10
});

The done callback on this page just populates the following table with a couple of fields from the metadata. The callback is called with the Search object as the argument, and the Search object contains an items object that contains a list for each zone searched. The callback is used to handle the results, because calling the query() method results in an asynchronous call to the Trove server that will return at some unknown time in the future.

function newspaper_search_done(s) {
    var idlink, snippet;
    for (var index in s.items[Trove.ZONES.NEWSPAPER]) {
        idlink = "<a href='" +
            s.items[Trove.ZONES.NEWSPAPER][index].troveUrl +
            "'>" +
            s.items[Trove.ZONES.NEWSPAPER][index].id +
            "</a>";
        snippet = s.items[Trove.ZONES.NEWSPAPER][index].snippet;
        newspapertable.append("<tr><td>" + idlink + "</td><td>" + snippet + "</td></tr>");
    }
}

Here's the results:

ID/LinkSnippet

Examples and Documentation

Please see the wiki for more examples.

There are API docs here and you can build HTML API pages using grunt jsdoc.