O'Reilly logo

Getting Started with Fluidinfo by Nicholas H. Tollervey, Nicholas J. Radcliffe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Programming Fluidinfo with JavaScript

The fluidinfo.js script is a small, self-contained library for using Fluidinfo in client-side JavaScript-based web applications.[25] Since Fluidinfo supports the emerging CORS (cross-origin resource sharing) standard, fluidinfo.js opens up the potential for sharing, using, and annotating open, linked data with Fluidinfo within your own web applications.

This chapter will be in two parts: a comprehensive description of fluidinfo.js followed by a detailed exploration of the steps taken to write a web-based book-reading application built using just fluidinfo.js and client-side JavaScript.

The fluidinfo.js library differs from the others examined so far in that it is asynchronous. It also provides developer-friendly capabilities through a set of functions to fulfill common tasks rather than an abstraction layer (like object orientation). These features are summarized in the following code snippet:

var options = {username: "alice", password: "secret"};
var session = fluidinfo(options);
var onSuccess = function(result) {
  // A callback to do something with the result
  console.log("OK");
  console.log(result);
};
var onError = function(result) {
  // A callback to handle when things go wrong
  console.log("ERROR");
  console.log(result);
};
session.query({
  select: ["fluiddb/about", "alice/rating", "alice/comment"],
  where: 'oreilly.com/title matches "Javascript"',
  onSuccess: onSuccess,
  onError: onError
});

Notice how an options object containing credentials ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required