This project has moved and is read-only. For the latest updates, please go here.

Displaying BSD triples in a browser

Aug 26, 2014 at 3:06 PM
Hi there,

I am planning to store in BSD data which should be available publicly. I would like to be able to display the results in the browser, formatted as turtle or HTML.

Is there a way to get data from BSD directly, by using a url to the endpoint, and passing the sparql query in the query string?

Also, would it be possible to pass a parameter to define the result format (turtle, HTML etc)

Aug 26, 2014 at 7:55 PM
Yes, if you use a SPARQL CONSTRUCT query you will get a result which is a collection of RDF triples. You can use the HTTP Accept header to specify the format you want to retrieve (the RdfFormat class in BrightstarDB provides a MediaTypes property which will give you the supported MIME type string).

HTML isn't supported as an output format (at the moment) but perhaps you could ask for RDF/JSON and use some client-side Javascript ?


Aug 27, 2014 at 10:03 AM
HI, Thank you.

Is there a way to get these results directly in the browser? using URL like http://localhost:8090/brightstar/MyStore/sparql?q=[sparql query]&format=json

(not by going to http://localhost:8090/brightstar/MyStore/sparql, and then running the query manually, but directly with a URL)

Or do I need to access the triples via code using BSD client?

Aug 27, 2014 at 11:34 AM
Yep, I think you almost got it correct :) http://localhost:8090/brightstar/MyStore/sparql implements SPARQL Protocol. So you can execute a query with a URL like http://localhost:8090/brightstar/MyStore/sparql?query=[sparql query].

In addition we support specifying the format as part of the query string (this isn't in the SPARQL Protocol spec, but its a useful feature), but you should use the MIME type string for the result format you want. For JSON this is application/json so your HTTP request would be http://localhost:8090/brightstar/MyStore/sparql?query=[sparql query]&format=application/json

This should all work from the browser - though depending on the browser you use it may not display the results but instead prompt you to save them somewhere - just depends on how it handles the application/json content type. It should also work from JS.

Note that we also support using HTTP POST (which may sometimes be necessary for long queries).


Aug 27, 2014 at 11:51 AM
Edited Aug 27, 2014 at 11:53 AM
Perfect, Thank you.

When I run select ?s ?p ?o where {?s ?p ?o} as below:


I do actually get the sparql endpoint user interface, with the query box populated with the query in the URL, and the result for the query populated in the result box (in XML format).

Is there anything that I am missing? I would like to get the results only, and in json...

Thanks :-)
Aug 27, 2014 at 11:55 AM
Ah, that's a bug then - if you pass a format parameter that should be switching off the HTML view. I'll log that one - hopefully it should be a quick fix.

However, if you are testing this to actually use the JSON from some JS code then it should work fine as long as you set the Accept header in your request (if you use jQuery I think it does this for you anyway).
Aug 27, 2014 at 12:00 PM
Great, thank you!