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 ...

Get Getting Started with Fluidinfo now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.