This page is part of the documentation of auKsys/5

WARNING auKsys/5 has been released as stable, but this documentation has not been fully updated with changes since auKsys/4. In case of questions or mistakes, you can use the support project.

This tutorial presents how to enable and access the kDB Web Server.

Enable the Web Server

The web server can only be enabled using C++ or the command line.

  • #include <kDBWebServer/EndPoint.h>
    
    kDBWebServer::EndPoint ep(kDBHostName, kDBPort);
    
  • When starting with auksys or kdb tools, it is possible to use the --web option:

    auksys start kdb/store --web
    kdb store --web
    

    The web-server command of kdb tool can also be used to start a web server for an already running store:

    kdb web-server
    

    This can be used to start a web server for a store started from python, ruby or as a ROS server.

Call the Web Server API

The web server API documentation is available in the kDBWebServer documentation. In this tutorial we present simple example to use that API to execute a SPARQL query.

  • Using python requests, which can be installed with:

    python -m pip install requests
    

    The following command can be used to execute the SELECT ?x ?y ?z WHERE {?x ?y ?z .} query on http://askco.re/graph#info and return a JSON file.

    import requests
    
    # Prepare the parameters for the query
    request = {"query": "SELECT ?x ?y ?z WHERE {?x ?y ?z .}", "Accept": "application/sparql-results+json", "default-graph-uri": "http://askco.re/graph#info"}
    
    # Execute the request
    response = requests.post("http://localhost:8888/sparql.html", data=request)
    
    # Parse the resulting json data
    json = response.json()
    
  • require 'net/http'
    require 'json'
    
    # Execute the request
    uri = URI('http://localhost:8888/sparql.html')
    res = Net::HTTP.post_form(uri, 'query' => 'SELECT ?x ?y ?z WHERE {?x ?y ?z .}', 'Accept' => 'application/sparql-results+json', 'default-graph-uri': 'http://askco.re/graph#info')
    
    # Parse the resulting json data
    json = JSON.parse(res.body)
    
  • The general template for calling the end point from the command line follow:

    curl "http://localhost:8888/sparql.html?query=<insert encoded query>&Accept=<insert encoded format>&default-graph-uri=<insert default graph>"
    

    The following command can be used to execute the SELECT ?x ?y ?z WHERE {?x ?y ?z .} query on http://askco.re/graph#info and return a JSON file.

    curl "http://localhost:8888/sparql.html?query=SELECT%20%3Fx%20%3Fy%20%3Fz%20WHERE%20%7B%3Fx%20%3Fy%20%3Fz%20.%7D&Accept=application%2Fsparql-results%2Bjson&default-graph-uri=http%3A%2F%2Faskco.re%2Fgraph%23info"
    

    Alternatively you can let curl encode the URL as POST, using:

    curl --data-urlencode "query=SELECT ?x ?y ?z WHERE {?x ?y ?z .}" --data-urlencode "Accept=application/sparql-results+json" --data-urlencode "default-graph-uri=http://askco.re/graph#info" http://localhost:8888/sparql.html