Good! I’m wanting to do a search engine with the framework stardog-js or node.js (I do sparql queries with the parameters of an input). I made an html file in which I refer to the “js” scripts. Now, how do I open the file with a browser? I have to use xampp or something like that?
Thank you very much from Argentina!
Goodnight! I am not knowing how to install and use the APIs to do sparql queries through JavaScript. I will be very grateful if you can help me.
Regards!
Hi,
We have a Quick Start example in the documentation that shows how to get started using stardog.js in a node.js application.
If you aren't making a node.js app, you could use something like Browserify to import the npm module in the browser.
You can do something like this in a browser application, after doing the npm install of stardog. Note that my username, etc. are from text inputs in my browser application (for example, for username, <input type="text" class="form-control" id="username" value="admin">
).
const conn = new stardogjs.Connection({
username: $('#username').val(),
password: $('#password').val(),
endpoint: $('#serverUrl').val()
});
stardogjs.query.execute(
conn,
$('#dbSelection').val(),
$('#query').val(),
'application/sparql-results+json',
{
limit: 10000,
offset: 0
}
).then(({ body }) => {
if (body.hasOwnProperty('results') && body.results.bindings.length === 0) {
alert('No results were returned for the query.');
} else if (body.hasOwnProperty('message')) {
alert('The query generated an error: \n' + 'Code: ' + body.code
+ '\nError: ' + body.message.substring(body.message.indexOf(':') + 1));
} else {
doSomething(body);
}
}).catch(error => {
alert(error);
});
This way, you don’t need Browserify.
Andrea
Great! Thank you very much!
I do not usually work with node js. Excuse my ignorance. How do I execute the code that shows me? I mean, do I need an apache server (xampp) or something like that? How do I organize the project to execute it? Again, sorry for my ignorance and thank you very much.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.