Giter VIP home page Giter VIP logo

export-service's Introduction

Export service

Microservice to export data using custom defined SPARQL queries.

Using the template

Extend semtech/mu-export-service and provide an export configuration in export.js.

Example Dockerfile

FROM semtech/mu-export-service:1.0.0
MAINTAINER Erika Pauwels <[email protected]>

Export configuration

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:

  • [REQUIRED] path: endpoint on which the export will be exposed
  • [REQUIRED] format: format of the export (application/json, text/csv, text/turtle, etc.)
  • [REQUIRED] query: the SPARQL query to execute. This may be a SELECT or a CONSTRUCT query.
  • [OPTIONAL] 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.

Using variables in the export query

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.

Example docker-compose

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

export-service's People

Contributors

erikap avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

export-service's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.