This document is part of the RAP - Rdf API for PHP documentation.
Phil Dawes <pdawes@users.sf.net>
Chris Bizer <chris@bizer.de>
Tobias Gauss <tobias.gauss@web.de>
Jan 2006
The RAP NetAPI is a server for publishing RDF models on the web. Models have URLs and they can be accessed by query using HTTP GET.
The RAP NetAPI provides an subset implementation of the W3C member submission RDF NetAPI and of a subset of the SPARQL Protocol. The NetAPI allows you to run an RDF server, with similar functionality as the Joseki RDF server, on web servers that provide PHP support. It is a simple alternative to Joseki that can be used in on cheap public webspace.
The RAP NetAPI implementation supports:
|
|
|
|
E.g. if you have a model in the RAP database with the following URI:
http://example.com/2004/testmodel1and you want to access it via the netapi endpoint at the following web URI:
http://myhostedwebspace.net/rdfapi-php/netapi/testmodelYou need to change the $modelmap array to contain the following entry:
|
The db: prefix indicates that the model is stored in the RAP database.
If you want to serve a RDF model that is stored in a local file in a netapi subdirectory:
subdirectory/testmodel2.rdfand you want to access it via the netapi endpoint at the following web URI:
http://myhostedwebspace.net/rdfapi-php/netapi/testmodel2You need to change the modelmap to contain the following entry:
|
The file: prefix indicates that the model is stored in a local file.
1. Downloading whole models
The easiest way to get started is to point an html browser at the URI endpoint for the model. E.g. for the above example, use
|
2. SPARQL Queries
The default query language of the RAP NetApi is SPARQL. So, if no additional lang parameter is given, the netapi will assume that the query uses the SPARQL query language. See also: RAP SPARQL tutorial.
Parameter Name | Parameter Type/Value | Description |
---|---|---|
query (required) | The query, as %encoded string |
The SPARQL query to be executed. The NetAPI supports SELECT, DESCRIBE, ASK and CONSTRUCT queries. |
Example SPARQL query:
|
The result of this query is returned in the SPARQL Query Results XML Format if it is a SELECT or an ASK query. If it is a CONSTRUCT or DESCRIBE query, the result is a serialisation of the corresponding graph and content type negotiation is used to determine the desired format..
3. Fetch Queries
The fetch query language returns all known information about a URIref. A query consists of single "r" parameter, whose value is the URIref. The exact extent of the RDF returned is dependent on the server. The NetAPI searches for all statements with the resource as subject, then calculates the bNode closure of all objects of these statements.
Parameter Name |
Parameter Value |
Description |
---|---|---|
lang (required) |
Id. of query language | URI: http://jena.hpl.hp.com/2003/07/query/fetch |
r (required) |
URIref | URIref of the resource |
|
4. RDQL Queries
See also: The RAP RDQL Tutorial
Parameter Name | Parameter Type/Value | Description |
---|---|---|
lang (required) |
Id. of query language | URI: http://jena.hpl.hp.com/2003/07/query/RDQL |
query (required) |
The query, as %encoded string | The RDQL query to be executed. As with all parameter values, this must be %-encoded. |
closure (optional) |
"true" or "false" | For each binding of a variable, which is bound to a bNode, the graph is augmented with the bNode closure from this point. |
Example RDQL query:
|
5. SPO Queries
SPO (also known as "Triples" or "find(SPO)") is an experimental minimal query language. An SPO query is a single triple pattern, with optional subject (parameter "s"), predicate (parameter "p"), and object (parameter "o", if a URIref, parameter "v" for a string literal). Absence of a parameter implies "any" for matching that slot of the triple pattern.
Parameter Name | Parameter Value | Description |
---|---|---|
lang (required) |
Id. of query language |
URI: http://jena.hpl.hp.com/2003/07/query/SPO |
s (optional) |
URIref |
URIref of the subject of the triple pattern. Absence implies a wildcard match. |
p (optional) |
URIref | URIref of the predicate of the triple pattern. Absence implies a wildcard match. |
o (optional) |
URIref | URIref of the object of the triple pattern. Only one of "o" and "v" may be given |
v (optional) |
String | Literal value as a string. Absence or "o" and"v" implies a wildcard match. |
closure (optional) |
"true" or "false" | Calculate the bNode closure of the matched subgraph. |
Example SPO query:
|
The netapi supports content type negotiation to determine the output RDF serialization format. E.g. to get the results of a fetch query in n3 format, do:
GET /rdfapi-php/netapi/testmodel?lang=fetch&r=http://example.com/myterm HTTP/1.0 Accept: application/n3The current implementation supports the following content mime types:
Note: A SPARQL query retuns an SPARQL Query Results XML Format document if it is a SELECT or ASK query or a serialisiation of the corresponding graph if it is a CONSTRUCT or DESCRIBE query.
To add and remove subgraphs from the store you need to send POST requests with an 'op' argument of 'add' or 'remove' and the rdf to add/remove in the body of the request. E.g.:
POST /rdfapi-php/netapi/testmodel?op=remove Content-type: application/n-triples Content-length: 353 ...RDF...
N.B. most http apis will add the content-length header for you, but you'll need to set the Content-type to be one of the above mime types.
Add and remove can be enabled in the config.inc by setting NETAPI_ALLOW_ADD and NETAPI_ALLOW_REMOVE to true. They are disabled by delault.