Microservice to export data using custom defined SPARQL queries
520
Microservice to export data using custom defined SPARQL queries.
Extend semtech/mu-export-service and provide an export configuration in export.js.
FROM semtech/mu-export-service:1.0.0
MAINTAINER Erika Pauwels <[email protected]>
The export.js file defines an array of export configuration objects as follows:
export default [
{
path: '/example',
format: 'text/csv',
query: `SELECT * FROM <http://mu.semte.ch/application> WHERE { ?s ?p ?o } LIMIT 100`,
file: 'export-example.csv'
},
...
];
Each element in the array will become an API endpoint in the microservice. An export configuration object consists of the following properties:
path: endpoint on which the export will be exposedformat: format of the export (application/json, text/csv, text/turtle, etc.)query: the SPARQL query to execute. This may be a SELECT or a CONSTRUCT query.file: name of the downloaded file. The filename may also be provided through a query param on the export request (e.g. /example?file=my-name.csv). If no filename is provided, the export will be displayed inline in the browser.You can also define variables in your SPARQL export query which will be replaced with query param values at runtime. Therefore, we use ES6's tagged template literals.
Import the template tag function from /app/template.js in your export.js and apply the tag function on your query. You can then define variables in your SPARQL query using ${['myVariable', 'type']}.
myVariable is the name of the variable that must be replaced.type is the datatype of the variable. This must be one of 'string', 'uri', 'int', 'float', 'date', 'dateTime', 'bool'.
At runtime the variable will be replaced with the value provided in the myVariable query param of the request.An example export.js including variables file may look as follows:
import template from '/app/template.js';
export default [
{
path: '/example',
format: 'text/csv',
query: template`SELECT * FROM <http://mu.semte.ch/application> WHERE { ?s a ${['class', 'uri']} } LIMIT 100`,
file: 'export-example.csv'
},
...
];
A GET request on /example?class=http://xmlns.com/foaf/0.1/Person will export the first 100 URIs of type foaf:Person.
If you don't want to build a new Docker image you can also run semtech/mu-export-service and mount your export configuration in /config.
version: '2',
services:
export:
image: semtech/mu-export-service:1.0.0
volumes:
- ./:/config
links:
- database:database
Content type
Image
Digest
Size
27 MB
Last updated
over 9 years ago
docker pull semtech/mu-export-service