Skip to content

Commit

Permalink
Use async and await in GET query route
Browse files Browse the repository at this point in the history
h/t cecemel
  • Loading branch information
peternowee committed Oct 6, 2023
1 parent 19b289d commit f7e03f8
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ app.get('/', function (req, res) {
res.send('Hello from virus-scanner-service');
});

app.get('/virus-scanner/query', function (req, res) {
var myQuery = `
SELECT *
WHERE {
app.get('/virus-scanner/query', async function (req, res) {
const myQuery = `
SELECT * WHERE {
GRAPH <http://mu.semte.ch/graphs/public> {
?s ?p ?o.
}
}`;

query(myQuery)
.then(function (response) {
res.send(JSON.stringify(response));
})
.catch(function (err) {
res.send('Oops something went wrong: ' + JSON.stringify(err));
});
try {
const response = await query(myQuery);
res.send(JSON.stringify(response));
} catch (err) {
res.send('Oops something went wrong: ' + JSON.stringify(err));
}
});

app.post(
Expand Down

0 comments on commit f7e03f8

Please sign in to comment.