Web Services

The features of the TopBraid platform can be accessed from web clients in various ways, for example via a built-in SPARQL end point. In addition to those bundled web services, TopBraid Live can also host any number of custom web services created by users/administrators. This page enumerates a few options on how to create such web services.

Common to all TopBraid custom web services is that they can be called either via GET or POST requests, and that they are created declaratively: the web services are stored in RDF and typically created with TopBraid Composer. This ensures that web services are seamlessly integrated with the data models/ontologies that they expose. Changes to an ontology will automatically update the web services etc. Furthermore, no "programming" in the traditional sense is needed to create those services.

SPARQLMotion

SPARQLMotion is an RDF-based scripting language with a graphical notations. SPARQLMotion scripts are data processing pipelines that can take some input (e.g. web service arguments), import and aggregate data from external sources, perform some processing (SPARQL etc) and export results in various formats.

Any registered SPARQLMotion script can be executed as a Web service. If the service call expects a response, a SPARQLMotion "exit point" module, such as ReturnText, ReturnXML, or Return RDF is required.

The following steps are required to register a SPARQLMotion script as a Web service:

Using the localhost server in TopBraid Composer-ME, the following URL format will call the Web service:
    http://localhost:8083/tbl/sparqlmotion?id=<service_name>&<argument1_name>=<argument1_value>...

Using a TopBraid Live server, the following URL format will call the Web service:
    http://<TBL_server_name>:<port>/tbl/tbl/sparqlmotion?id=<service_name>&<argument1_name>=<argument1_value>...

See: DBPediaCountryCapitals Service for two examples of web services created with SPARQLMotion.

Note that SWP (see below) provides an alternative syntax for exposing SPARQLMotion functionality as web services.

The SPARQLMotion servlet provides mechanisms for tracking the progress of long-running operations, and for uploading binary files. See the page on the SWP servlet for details on the _progressId and _fileUpload arguments.

SPIN Templates

In a nutshell, a SPIN Template is a SPARQL query that can take parameters which are mapped to pre-bound variables. A template is a bit like a stored procedure from SQL databases in that it encapsulates a complex query and gives it a name.

A TopBraid Live server exposes SPIN templates as web services, as described here.

SPARQL Web Pages (SWP)

SPARQL Web Pages (SWP) is probably best known for its ability to create HTML renderings of RDF data, but it can also produce any other textual serialization including JSON or XML. An SWP web service looks almost like a SPARQLMotion or SPIN template service in that it is a class that declares the arguments as spl:Arguments. However, SWP services also need to declare their result type, e.g. ui:JSON as value of the ui:responseType property. Here is the upper part of an example SWP web service that produces some JSON consumed by the current EDG tree component:

(The ui:responseType of that service is "inherited" from the superclass ui:JSONServices.) The actual work that the service has to perform when called is declared in the lower section of that service definition:

This particular service is using some helper template to compute the shortest path from a given node to a given root, and then serializes the whole result set to a JSON array using the built-in helper element swon:RSArray. SWP is much more powerful than SPIN templates because it includes sophisticated control elements such as if-then-else and forEach. Furthermore, SWP services can also include most of the SPARQLMotion modules in a compact textual notation.

Saved Searches

TopBraid EDG includes a powerful search form that can be used to filter instances of a given class by some properties, for example to find "All Islands that have a size smaller than 1000 square kilometres":

There is a little Save button under the search form, allowing users to save the current search form so that it can be restored later. As a side effect, any of those saved searches can also be called as a web service with the URL provided by the dialog as shown below:

You can copy and paste the URL of the service from the dialog above, and it may produce any of the standard result formats.