Skip to content

Commit 6964bf3

Browse files
committed
Initial commit
0 parents  commit 6964bf3

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*~
2+
node_modules/

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM semtech/mu-javascript-template:1.0.0
2+
3+
MAINTAINER Erika Pauwels <erika.pauwels@gmail.com>

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Export JS Template
2+
==================
3+
4+
Microservice to export data using custom defined SPARQL queries.
5+
6+
7+
## Using the template
8+
Extend the `semtech/mu-export-js-template` and add an export configuration in `/config/queries.js`.
9+
10+
The configuration file defines an array of export configuration objects as follows:
11+
12+
```javascript
13+
export default [
14+
{
15+
path: '/all',
16+
format: 'text/csv',
17+
file: 'export-100.csv',
18+
query: `SELECT * FROM <http://mu.semte.ch/application> WHERE { ?s ?p ?o } LIMIT 100`
19+
},
20+
...
21+
];
22+
23+
```
24+
25+
An export configuration object consists of the following properties:
26+
* [REQUIRED] `path`: endpoint on which the export will be exposed
27+
* [REQUIRED] `format`: format of the export (`application/json`, `text/csv`, etc.)
28+
* [OPTIONAL] `file`: name of the attachment file containing the export. If no filename is provided, the export will be displayed inline in the browser.
29+
* [REQUIRED] `query`: the SPARQL query to execute. This may be a `SELECT` or a `CONSTRUCT` query.
30+
31+
## Example Dockerfile
32+
33+
```
34+
FROM semtech/mu-export-js-template:1.0.0
35+
MAINTAINER Erika Pauwels <erika.pauwels@gmail.com>
36+
COPY queries.js /config
37+
```

app.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { app } from 'mu';
2+
import request from 'request';
3+
4+
import queries from '/config/queries';
5+
6+
queries.map(function(config) {
7+
app.get(config.path, function(req, res, next) {
8+
const options = {
9+
method: 'POST',
10+
url: process.env.MU_SPARQL_ENDPOINT,
11+
encoding: 'utf8',
12+
headers: {
13+
'Accept': config.format
14+
},
15+
qs: {
16+
format: config.format,
17+
query: config.query
18+
}
19+
};
20+
21+
request(options, function(error, response, body) {
22+
if (error) {
23+
console.error(`Something went wrong executing the SPARQL query: ${JSON.stringify(error)}`);
24+
next(error);
25+
} else if (response.statusCode == 200) {
26+
if (config.file) { res.attachment(config.file); }
27+
res.send(body);
28+
} else {
29+
next(new Error(body));
30+
}
31+
});
32+
} );
33+
});

0 commit comments

Comments
 (0)