In part 1 of this post I described the new HTTP Port in Construct. In this part of the post I’ll explain how to write a web form and style the return values.
SPARQL Query
You can send a query to Construct with GET or POST. Here is how we do it in HTML with GET:
-
<form method=“GET” action=“http://duvel.ucd.ie:8888/”>
-
<textarea name=“q” cols=“64″ rows=“10″>SELECT ?subject ?predicate ?object WHERE {?subject ?predicate ?object}</textarea><br/>URL of XSLT to apply (optional):<br/><input type=“text” name=“xsl” size=“56″ value=“http://www.construct-infrastructure.org/stylesheets/default.xsl type=”submit” value=”Submit Query“>
-
</form>
the only thing the HTTP Port wants is the query field to be called either “q” or “query”. The returned XML will be sent back to your browser. Something like this:
-
<?xml version=“1.0″?>
-
<?xml-stylesheet type=“text/xsl” href=“http://duvel.ucd.ie:8888/xsl/www.construct-infrastructure.org/stylesheets/default.xsl”?>
-
<sparql
-
xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
-
xmlns:xs=“http://www.w3.org/2001/XMLSchema#”
-
xmlns=“http://www.w3.org/2005/sparql-results#”>
-
<head>
-
<variable name=“subject”/>
-
<variable name=“predicate”/>
-
<variable name=“object”/>
-
</head>
-
<results>
-
<result>
-
<binding name=“subject”> <uri>http://www.pervasive-ontologies.org/ontologies/sensors/bluetooth#reading00:19:63:96:56:01@00:80:98:94:AE:4B@1201631502</uri>
-
</binding>
-
<binding name=“predicate”>
-
<uri>http://www.pervasive-ontologies.org/ontologies/sensors/bluetooth#spotted</uri>
-
</binding>
-
<binding name=“object”>
-
<literal>00:19:63:96:56:01</literal>
-
</binding>
-
</result>
-
</results>
-
</sparql>
To make the results look neater you can apply and XSL stylesheet. Send the URL for the XSL stylesheet as a field “xsl” in the form. This stylesheet must be web accessible. We’ve made a default example stylesheet you can use to get started.
Inserting N-3 RDF Data
You can insert new data into Construct using a form like this (we’re using POST this time for variety but GET works too):
-
<form method=“POST” action=“http://duvel.ucd.ie:8888/”>
-
<textarea name=“i” cols=“64″ rows=“10″><http://www.pervasive-ontologies.org/ontologies/sensors/bluetooth#reading00:19:63:96:56:01@00:80:98:94:AE:4B@1201631502><http://www.pervasive-ontologies.org/ontologies/sensors/bluetooth#spotted>“00:19:63:96:56:01″.</textarea><br/>Expiry time for data (optional):<br/><input type=“text” name=“expiry” size=“15″ value=“20000″><br/><input type=“submit” value=“Submit Data”>
-
</form>
in this form you send the data to be inserted as a field “i” or “insert”.
The returned data from an insert is an XML document with a status code and any messages given back from Construct. It looks something like this:
-
<response>
-
<status>OK</status>
-
<description>The data <http://www.pervasive-ontologies.org/ontologies/sensors/bluetooth#reading00:19:63:96:56:01@00:80:98:94:AE:4B@1201631502><http://www.pervasive-ontologies.org/ontologies/sensors/bluetooth#spotted>“00:19:63:96:56:01″. with given expiry 20000 was passed to the Construct data store without error.
-
</description>
-
</response>
Well, that is about it. You can make calls to Construct over HTTP from browsers or web applications using the HTTP Port. Have fun.
![[del.icio.us]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/digg.png)
![[Google]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/google.png)
![[StumbleUpon]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Windows Live]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/email.png)
0 Responses to “HTTP Port - Part 2”
Leave a Reply