Setting up a SPARQL endpoint

On this page

    The SPARQL protocol allows clients to send SPARQL queries to Web servers over HTTP, and query results to be sent back to the client. Comunica SPARQL can be used to set up a SPARQL endpoint on top of any number of sources you want.

    1. Installation

    Since Comunica runs on Node.js, make sure you have Node.js installed on your machine.

    Next, we can install Comunica SPARQL on our machine:

    $ npm install -g @comunica/actor-init-sparql

    2. SPARQL endpoint over one source

    After installing Comunica SPARQL, you will be given access to several commands including comunica-sparql-http, which allows you to start a SPARQL endpoint from the command line.

    This command requires one or more URLs to be provided as sources to query over.

    For example, the following command starts a SPARQL endpoint over DBpedia:

    $ comunica-sparql-http
    Given a URL, Comunica will automatically detect the type of source and handle it accordingly.

    By default, the endpoint will be exposed on port 3000. Your endpoint will now be live on http://localhost:3000/sparql. Any client that understands the SPARQL protocol will now be able to send queries to this URL, such as fetch-sparql-endpoint, or even Comunica itself.

    The URL http://localhost:3000/ will automatically redirect to http://localhost:3000/sparql.

    You can easily test query execution over your endpoint using a tool such as curl. The SPARQL protocol allows sending queries via HTTP GET by passing a URL-encoded SPARQL query via the ?query= parameter:

    $ curl -v "http://localhost:3000/sparql?query=CONSTRUCT%20WHERE%20%7B%3Fs%20%3Fp%20%3Fo.%7DLIMIT%20100"

    3. SPARQL endpoint over multiple sources

    One key feature of Comunica is its ability to query over multiple sources. For this, you can just supply any number of URLs as arguments.

    $ comunica-sparql-http \ \

    4. Changing the port

    Using the -p option, the port can be changed:

    $ comunica-sparql-http \
      -p 3001

    5. Increasing the number of worker threads

    Using the -w option, the number of parallel worker threads can be set:

    $ comunica-sparql-http \
      -w 4

    Setting this to the number of available CPU cores tends to give the best performance.

    6. Learn more

    This guide only discussed the basic functionality of comunica-sparql-http. You can learn more options by invoking the help command:

    $ comunica-sparql-http --help
      comunica-sparql-http hypermedia@
      comunica-sparql-http -c context.json
      comunica-sparql-http -c "{ \"sources\": [{ \"type\": \"hypermedia\", \"value\" : \"\" }]}"
      -d            the destination for update queries
      -c            context should be a JSON object or the path to such a JSON file.
      -p            the HTTP port to run on (default: 3000)
      -t            the query execution timeout in seconds (default: 60)
      -w            the number of worker threads (default: 1)
      -b            base IRI for the query (e.g.,
      -l            Sets the log level (e.g., debug, info, warn, ... defaults to warn)
      -i            a flag that enables cache invalidation before each query execution.
      -u            enable update queries (by default only read queries are enabled)
      --lenient     if failing requests and parsing errors should be logged instead of causing a hard crash
      --help        print this help message
      --version     prints version information