Web APIs from SPARQL queries
BASIL is a middleware between SPARQL endpoints and applications. You store a SPARQL query, BASIL publishes it as a Web API, with parameters, multiple output formats, views and Swagger documentation.
Current release: 1.0.0 · Java 21 · Apache Jena 6 · Apache License 2.0
# 1. A SPARQL query; ?_entity_iri becomes a parameter
SELECT ?type WHERE { ?_entity_iri a ?type }
# 2. Store it as an API
curl -u user:pass -X PUT http://localhost:8080/basil \
-H "X-Basil-Endpoint: https://dbpedia.org/sparql" \
-T query.rq
→ {"location":"http://localhost:8080/basil/s50nwb9679dd"}
# 3. Call it, in the format you need
curl "http://localhost:8080/basil/s50nwb9679dd/api.json\
?entity=http://dbpedia.org/resource/Rome"
What BASIL does
Queries become APIs
An API is a SPARQL endpoint plus a query. Input parameters are declared in the query itself, by a simple variable naming convention.
Many output formats
JSON, XML and CSV without namespaces, for developers not familiar with Linked Data, and RDF formats (Turtle, N-Triples, RDF/XML, JSON-LD) for those who are.
Views
Post-process results with Mustache templates or JavaScript, for example to produce an HTML snippet ready to embed in a page.
Self-documenting
Every API has a Swagger description, a name and a description, and can be reached through human-readable aliases.
Safe substitution
Parameter values are serialised as RDF terms before the query is parsed, so a value cannot change the structure of the query.
Reusable library
The query-parameter module is a small Java library, used also by other projects, such as SPARQL Anything.
How it works
- Write a query. Variables starting with an underscore are parameters:
?_nameis mandatory,?__nameoptional, a suffix gives the type, e.g.?_city_irior?_limit_number. - Store it. A
PUTto/basilwith the endpoint and the query creates a new API with a stable identifier. - Use it.
GET /basil/{id}/api?name=valuebinds the parameters, executes the query on the endpoint, and returns the result in the requested format. - Manage it. Sub-resources
/spec,/view,/docs,/alias,/explainand/api-docslet you inspect and maintain the API over HTTP.
BASIL has no graphical interface of its own: it is controlled entirely through its HTTP API. See the REST API reference.
Get started
Download basil-server-1.0.0.jar, basil-server.ini and log4j2.xml from the releases page, then:
java -jar -Dbasil.configurationFile=./basil-server.ini \
-Dlog4j.configurationFile=./log4j2.xml \
basil-server-1.0.0.jar -p 8080
Data is stored in ./basil-data (Apache Jena TDB2). Continue with the quick start, or use BASIL as a Java library.
About
BASIL (Building APIs SImpLy) was developed at the Knowledge Media Institute, The Open University, by Enrico Daga and Luca Panziera, and is released under the Apache License 2.0. Contributions, bug reports and questions are welcome on the issue tracker.
Citing BASIL
Enrico Daga, Luca Panziera, Carlos Pedrinaci. A BASILar Approach for Building Web APIs on top of SPARQL Endpoints. In: Proceedings of the Third Workshop on Services and Applications over Linked APIs and Data (SALAD 2015), CEUR Workshop Proceedings, vol. 1359, pp. 22–32, 2015. PDF
Enrico Daga, Luca Panziera, Carlos Pedrinaci. BASIL: A Cloud Platform for Sharing and Reusing SPARQL Queries as Web APIs. ISWC 2015 Posters & Demonstrations, CEUR Workshop Proceedings, vol. 1486, 2015. PDF