Skip to content

SPARQL Endpoint Setup

bnowack edited this page Nov 12, 2012 · 4 revisions

ARC2 makes the creation of SPARQL endpoints very easy. There is a protocol-compliant endpoint class which can be used for HTTP-based data access:

/* ARC2 static class inclusion */ 
include_once('path/to/arc/ARC2.php');

/* MySQL and endpoint configuration */ 
$config = array(
  /* db */
  'db_host' => 'localhost', /* optional, default is localhost */
  'db_name' => 'my_db',
  'db_user' => 'user',
  'db_pwd' => 'secret',

  /* store name */
  'store_name' => 'my_endpoint_store',

  /* endpoint */
  'endpoint_features' => array(
    'select', 'construct', 'ask', 'describe', 
    'load', 'insert', 'delete', 
    'dump' /* dump is a special command for streaming SPOG export */
  ),
  'endpoint_timeout' => 60, /* not implemented in ARC2 preview */
  'endpoint_read_key' => '', /* optional */
  'endpoint_write_key' => 'REPLACE_THIS_WITH_SOME_KEY', /* optional, but without one, everyone can write! */
  'endpoint_max_limit' => 250, /* optional */
);

/* instantiation */
$ep = ARC2::getStoreEndpoint($config);

if (!$ep->isSetUp()) {
  $ep->setUp(); /* create MySQL tables */
}

/* request handling */
$ep->go();

Instead of the go() method, which will automatically send HTTP headers and the query result , you can also do the processing manually (e.g. if you want to adjust the result somehow):

/* request handling */
$ep->handleRequest();
$ep->sendHeaders();
echo $ep->getResult();

In case of an empty request, the endpoint will generate an HTML form. Custom result formats such as SPARQL/JSON can be specified via HTTP Accept Headers, or by adding a "format" argument to the request URI.

The endpoint also supports a "jsonp" or "callback" parameter which will wrap JSON results in parentheses and prepend the passed parameter value (e.g. &callback=handleSPARQLResult).

API keys for read (select, ask, describe, construct, dump) and/or write (load, insert, delete) operations, can be passed via a "key" parameter.