W3C home > Mailing lists > Public > semantic-web@w3.org > March 2005

URI-Triples: RDF serialization for use in query strings

From: Benja Fallenstein <benja.fallenstein@gmail.com>
Date: Sun, 13 Mar 2005 01:39:56 +0100
Message-ID: <ff7ba12a0503121639366b7f19@mail.gmail.com>
To: semantic-web@w3.org


I was pondering RESTful RDF-in-RDF-out web services, i.e. RESTful
services that take RDF as input and return it as output. For POST it's
obvious how to do that, for GET a way to encode graphs in a URI query
string is needed. Of course, you could just %-escape the N-Triples
serialization of a graph, but that's not very readable, and even more
verbose than necessary (and we don't like that in URIs :-)).

So I cooked up a new serialization -- "URI-Triples" -- and wrote a
quick Python parser/serializer.

Here's an example graph in encoded N-Triples:


Here's the same in URI-Triples:


You could also %-encode Turtle, which may sometimes give you even more
brevity, but less readability, because the ; and , delimiters are hard
to see in the URI encoded string; here's an example:


Make up your own mind, but I think the (relative!) brevity and
readability win. When you happen to have one in the location bar of
your browser, you actually stand a chance to figure out how it works
and tinker with it. [Maybe it's just me, but I've always felt web
services ought to be explorable with your browser like that =-)]

You can get the source code from


I'm too lazy to do a second write-up of the details, so below, I'll
just copy the code documentation:

A parser and serializer for the URI-Triples serialization of RDF.

Author:   Benja Fallenstein <benja.fallenstein@gmail.com>
Homepage: http://himalia.it.jyu.fi/~benja/uritriples/

WARNING: Currently the parser and serializer perform
only very incomplete checks, i.e. if you pass garbage in,
you may get garbage out instead of an error message.
This should change soon.

URI-Triples is an RDF serialization that you can put into a URI query string.
I just cooked the format up (on 2005-03-13) -- this is gonna be
the reference implementation...

URI-Triples is intended for RESTful RDF-in-RDF-out web services, i.e.
so that you can use GET with web services that take an RDF graph as input.

The syntax is designed to be as readable as I could make it
for something that you can put inside a URI. (If it didn't
have to be readable, you could of course just %-escape N-Triples.)

Here is an example URI-Triples serialization:


Here is the same graph in Turtle:

    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
    @prefix dc:  <http://purl.org/dc/elements/1.1/>.

    _:foo rdf:type <http://example.org/types/Document>;
          dc:title "War and Peace"@en, "Krieg und Frieden"@de.

Here is an informal grammar:

query_string := (stmt "_|_")* stmt
stmt         := prefix | triple
prefix       := name "_=_" uri
triple       := (node | bnode) "_;_" node "_;_" (node | bnode | literal)
node         := qname | uri
qname        := name "." name
bnode        := "." name
literal      := "'" text "'" ("" | "@" langtag | "^^" node)

'uri' is a %-escaped version of the UTF-8 serialization of a URIRef 
as defined in the RDF specs.

'text' is a %-escaped version of the UTF-8 serialization of the content
of a literal, as defined in the RDF specs.

I'm not sure about 'name'; it may be just [a-zA-Z0-9]*, or it may be
a %-escaped version of the UTF-8 serialization of an arbitrary string...
do we need the latter for internationalization? But what does it help,
if unquoting (to get the non-ASCII characters) makes the string ambiguous
(as _ could either be from URI-Triples or from the unquoted URI)?

For now, better assume that 'name' is [a-zA-Z0-9]*.
If you have an opinion about this, mail me.

Opinions about URI-Triples, please? :-)

- Benja
Received on Sunday, 13 March 2005 02:42:02 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 08:44:52 UTC