Back to all updates

over 7 years ago

Save 50 Lines of Code Using Sciverse Search JavaScript API

To make an OpenSocial request and parse the results of a response from any Open API can be quite time consuming, especially when you are not familiar with the Open API in question. Although the RESTful protocol of an Open API request with a JSON response format is already a great simplification compared to the Web Services and XSD Schema protocol. When mashing up Open APIs and Open Data, the greatest challenge is often how to properly build and send a request, and how to correctly parse and display the response data, even if in 90% of the cases a developer is looking for the same simple answer, often a list of results from a simple query.

This obscure challenge is not different for many developers on SciVerse as it is on other Open API platforms. Using a JavaScript API therefore allows you to hide many of the cumbersome implementation details, saving you development time and agony.

This following code demonstrates how you can use a simple JavaScript API like the SciVerse Search JavaScript API to make a SciVerse Content API call to ScienceDirect and display a list of search results in an HTML div element.

blog post photo
Figure 1: simplified code to make a SciVerse Content API call to ScienceDirect

The Simple SciVerse Search example above hides about 50 lines of code and reduces the SciVerse Content API call to ScienceDirect to precisely 7 lines of code, while enormously simplifying the call.

To enable this simplified script in your SciVerse application, simply include the JavaScript API in your gadget specification file and set the UserPref properties for the API-key and the AuthToken.

blog post photo
Figure 2: simply include the JavaScript API for the shared views

blog post photo
Figure 3: include these User Pref properties

If you would like to add certain features that are currently not included in the Simple SciVerse Search API, go to Github and make the change, or send me an email to include the feature at developer at elsevier dot com.

With thanks to:

  • Sam Adams, who wrote the original version of the SciVerse Search API during the Elsevier Dev8D 2011 Challenge, winning the 1st prize of $1500;
  • Mahendra Mahey and DevCSI for organizing Dev8D; and
  • JISC for sponsoring Dev8D.

Source Code:
github examples repo

Example app using the Simple SciVerse Search API: https://raw.github.com/sciversedev/examples/master/javascriptapi/simple-sciverse-search-example-app1.xml

Simple SciVerse Search JavaScript API: https://raw.github.com/sciversedev/lib/master/simple-sciverse-search.js

blog post photo

Sam Adams original sciverse-search.js: https://bitbucket.org/sea36/sciverse-dev8d/overview