diff --git a/app.py b/app.py index 59b16e1..3cff1ad 100644 --- a/app.py +++ b/app.py @@ -36,6 +36,10 @@ def quickstart(): def about(): return render_template('about.html') +@app.route('/api') +def api(): + return render_template('api.html') + @app.route('/docs') def docs(): return render_template('docs.html') diff --git a/templates/api.html b/templates/api.html new file mode 100644 index 0000000..1b567ce --- /dev/null +++ b/templates/api.html @@ -0,0 +1,69 @@ +{% extends "base.html" %} + +{% block content %} +
+

ShExStatements API

+ +

Operations

+

ShExStatements has also a public API that can be easily accessible both on a local installation as well as on the public interface. It has one operation that takes as input a JSON array with two elements as given below:

+ +

It returns a JSON array with one element containing the ShEx (shape expression).

+

Example JSON input

+

Take for example the file tvseries.json (also present in examples/api/tvseries.json). It is an array with two elements.

+
+
+[
+"|",
+"wd|<http://www.wikidata.org/entity/>|||\n
+wdt|<http://www.wikidata.org/prop/direct/>|||\n
+xsd|<http://www.w3.org/2001/XMLSchema#>|||\n
+\n
+@tvseries|wdt:P31|wd:Q5398426|# instance of a tvseries\n
+@tvseries|wdt:P136|@genre|*|# genre\n
+@tvseries|wdt:P495|.|+|#country of origin\n
+@tvseries|wdt:P57|.|+|#director\n
+@tvseries|wdt:P58|.|+|#screenwriter\n
+@genre|wdt:P31|wd:Q201658,wd:Q15961987|#instance of genre\n"
+]
+
+
+

Calling ShExStatements API

+

Following is the way to call the ShExStatements API

+
+
+$ curl -s http://127.0.0.1:5000/ -X POST -H "Accept: application/json"  --data  @examples/api/tvseries.json |sed 's/\\n/\n/g'
+
+
+

or

+
+
+$ curl -s https://shexstatements.toolforge.org/ -X POST -H "Accept: application/json"  --data  @examples/api/tvseries.json |sed 's/\\n/\n/g'
+
+
+ +

Example JSON output response

+

It gives the following output. For the output, the above command makes use of sed.

+
+
+"PREFIX wd: <http://www.wikidata.org/entity/>
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+PREFIX wdt: <http://www.wikidata.org/prop/direct/>
+start = @<tvseries>
+<tvseries> {
+  wdt:P31 [ wd:Q5398426  ] ;# instance of a tvseries
+  wdt:P136 @<genre>* ;# genre
+  wdt:P495 . ;#country of origin
+  wdt:P57 . ;#director
+  wdt:P58 . ;#screenwriter
+}
+<genre> {
+  wdt:P31 [ wd:Q201658 wd:Q15961987  ] ;#instance of genre
+}
+"
+
+
+ +{% endblock %} diff --git a/templates/base.html b/templates/base.html index 3ad8064..d673f41 100644 --- a/templates/base.html +++ b/templates/base.html @@ -22,6 +22,7 @@
  • Home
  • Quick Start
  • Documentation
  • +
  • API
  • About