RDF/POST Encoding for RDF

This Version
Latest Version
Sergei Egorov <esl@ariadnegenomics.com>

Copyright © 2006 Sergei Egorov

This work is licensed under a Creative Commons License.

Table of Contents


The Resource Description Framework (RDF) is the basic knowledge representation model for the W3C Semantic Web initiative. RDF/POST is an encoding method allowing the transfer of RDF data via the traditional HTTP GET and HTTP POST mechanism, facilitating the creation of RDF-in/RDF-out web services with dual interfaces (direct programmatic access and human-friendly entry and result pages).

HTML Forms and MIME application/x-www-form-urlencoded Format

The W3C HTML 4 Forms recommendation specifies the behavior of HTTP user agents and includes a short description of the format used for submission of form data (MIME type application/x-www-form-urlencoded). The format is rather simple; its data model is an ordered list of key/value pairs, where keys and values are just strings. As implemented in modern browsers, the format has its limitations, but there is nothing preventing one from using (a profile of) it to serialize any RDF graph.

The proposed serialization is straightforward and rather concise, which makes it suitable for use with HTTP GET (URLs over 2K in length run a risk of causing "414 Request URL Too Long" reply from the server). It inherits the abbreviated tree form from Turtle (and N3, further up the ancestry line), using different keys for subject, predicate, and object to eliminate the need for punctuation.

Extended Backus-Naur Form (EBNF) Grammar

This EBNF is the notation used in XML 1.0 second edition.

rdf::='rdf=' def_ns_decl? ns_decl* triples*
def_ns_decl::='&v=' uri_prefix
ns_decl::='&n=' name '&v=' uri_prefix
triples::=subj property*
subj::=blank_subj | uri_subj | def_ns_subj | ns_subj
blank_subj::='&sb=' name
uri_subj::='&su=' uri
def_ns_subj::='&sv=' uri_suffix
ns_subj::='&sn=' name '&sv=' uri_suffix
property::=pred obj*
pred::=uri_pred | def_ns_pred | ns_pred
uri_pred::='&pu=' uri
def_ns_pred::='&pv=' uri_suffix
ns_pred::='&pn=' name '&pv=' uri_suffix
obj::=blank_obj | uri_obj | def_ns_obj | ns_obj | literal_obj
blank_obj::='&ob=' name
uri_obj::='&ou=' uri
def_ns_obj::='&ov=' uri_suffix
ns_obj::='&on=' name '&ov=' uri_suffix
literal_obj::='&ol=' string type_or_lang? | type_or_lang '&ol=' string
type_or_lang::=type | lang
type::='&lt=' uri
lang::='&ll=' lang_id
uri::=string    /* URI as defined in RFC3986 */
uri_prefix::=uri    /* any valid URI prefix */
uri_suffix::=uri    /* any valid URI suffix */
lang_id::=string    /* see xml:lang */
name::=[A-Za-z][A-Za-z0-9]*     /* same as in N-Triples */
string::=(schar | plus | echar)*     /* unreserved or urlencoded */
schar::=[A-Za-z0-9.,;:'/?!$@()*~_-]     /* safe as per RFC3986 */
plus::='+'     /* encodes single space (#x20) */
echar::='%'[0-9A-Fa-f][0-9A-Fa-f]   /* encodes one octet */

The use of this format in HTML pages relies on the "fields are listed in the order they appear" requirement of the HTML Forms specification. Since HTML user agents are not required to send fields with null values (browsers are free to ignore them), such fields should not be used to send pairs which are important for correct decoding of the format (e.g. a pair defining the subject of a triple). Remember that hidden fields are always sent if they have VALUE attributes present.

To handle data submitted from HTML forms, the decoder should allow for some missing pairs, skipping to the next sync point (if any) and silently ignoring the affected triples:

Strings can contain any Unicode character encoded in UTF-8 and, if the resulting octets fall outside of US_ASCII, urlencoded as described in Form content types - application/x-www-form-urlencoded. The simplest way to ensure that browsers send form data in UTF-8 is to encode form pages in UTF-8.


Here is a simple RDF/POST document encoded in HTTP GET URL:

Someone called Ora Lasilla wrote a book titled "Moby Dick" .

The same document can be encoded in a simple HTML form:

Someone called titled

In both examples the query part is constructed as follows (spaces and indentation are added for presentation purposes):

&n=rdf &v=http://www.w3.org/1999/02/22-rdf-syntax-ns%23
&n=dc &v=http://purl.org/dc/elements/1.1/
 &pn=dc &pv=creator
 &pn=rdf &pv=type
 &pn=dc &pv=title

It can be compared line-by-line with the equivalent Turtle description:

@prefix : <http://xmlns.com/foaf/0.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns%23> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
  "Ora" ;
  "Lasilla" ;
  _:b .
  :Document ;
  "Moby Dick" .

If one wants to make sure that submitted data conforms to RDF datatype requirements, e.g. does not contain unexpected empty string values and incorrectly formatted dates, the forms can be validated with Javascript code. Javascript validation in the form is based on the code written by Stephen Poley. If you view this page HTML source, you will notice that form controls are referenced by their 'id' attribute, not by their 'name' attribute used in forming the actual HTTP POST data.

note type
author Required
email Required
This is an RDF/POST Form

Media Type

As a rule, RDF/POST data is sent with application/x-www-form-urlencoded media type; if one needs to distinguish RDF/POSTs from regular posts, a more specific application/rdf+x-www-form-urlencoded media type can be used (not yet registered with IANA). Encoding considerations are the same in both cases; RDF/POSTs can be distinguished by the "rdf=" prefix ("magic number").

Recommended file extension is .rpo


RDF/POST parser/converter used in live examples on this page can be downloaded here (C, Linux/Windows). If you have a tool you would like to see mentioned here, send e-mail to the address at the top of the page.


This work is licensed under a Creative Commons License.

The following section is informational only, please refer to the Original License for complete license terms.

This license grants the following rights:

This license imposes the following restrictions: