About
This is the development journal for the Semantic Web API project. It is a standard interface for accessing RDF data through multiple clients. Sponsored by Semedia and Google.
Membership
Name:James Cerra
Location:Pittsburgh, Pennsylvania, United States
Recent Entries

Wednesday, July 13, 2005

Dialogue and Apache

Small update. I added a dialog between Giovanni Tummarello (mentor) and Jeen Boekstra (of Openrdf.org) that took place a few weeks ago. Lots of insight between them.

Apache Madness

I also configured Apache to serve a description of the project at the same URI as the HTML home page. This is because both the web site and the DOAP document describe the project. That is, each are different representations of the same thing. One is human-readable while the other is computer literate. So they both refer to the same resource - the project for SWAPI.

Type Maps

I had a hard time coaxing Apache into doing content negotiation. My first attempt involved type maps (with extension var). To get it working.... I had to call the Apache type map file index.html.var since Apache by default looks for anything named index.html - yuck! The contents of the file was:

URI: home.html
Content-type: text/html

URI: doap.html
Content-type: application/rdf+xml

What that does is set two documents to be loaded depending on the content type specified by the user agent requesting the resource.

MultiViews

Christopher Schmidt pointed out a better way to configure Apache to do this. You scrap the var file becuase it is now redundant. Instead, you configure the .htaccess file (that's the entire file name) to have the content:

Options +Multiviews
AddHandler type-map var
DirectoryIndex index
AddType application/xhtml+xml;qs=0.9 .xhtml+xml .xhtml
AddType text/html;qs=.9 .html
AddType application/rdf+xml;qs=0.8 .rdf+xml .rdf
AddType application/xml;qs=0.3 .xml

The first line tells Apache to use MultiViews. This lets it automatically fake a type map based on the file extensions of a file. The second line is unimportant (it just lets type maps work, but they aren't necessary anymore).

The third line instructs Apache to look for evey file with name minus extensions named index. Think of it like index.* (but it also matches index.en.html and index.html.fr for example). Then you put multiple files in a directory and modify their extensions. A user agent will tell Apache which content-types it wants; Apache will automatically select the appropriate file and serve that as the index. I used the files:

  • index.html
  • index.xhtml+xml
  • index.rdf+xml

So how does Apache determine which file to send? That's what the last lines do. They instruct Apache to server anything a certain extension (like html) as a certain content-type (like text/html). The ;qs= parts are strings that modfiy the "quality" of representations in that media type. They range from 0 to 1, where 1 means the perferred representation to serve, while 0 means the worst type to serve. For example, an image/png document may be the perferred form of the Mona Lisa, while a text/plain document (with ASCII art) is the worst besides a 404 of course. So those last lines say how to serve each type, and that:

  1. application/xhtml+xml and text/html are the best forms.
  2. application/rdf+xml is the next best type
  3. application/xml is not a good type, but better than some

Web browsers also rank they're perferred content-types too. As I understand it. They will send a list of types they accept, and how important each is to the browser. Apache will filter out the ones it doesn't support, then the web browser's lower ranked ones (below the highest available ones), and filter out all but the best from .htaccess, then a random one from the final list (you should only have one here for consistancy).

This way, you can serve application/xhtml+xml to Mozilla and Opera, text/html to Internet Explorer (which doesn't support the XHTML media type), and applcation/rdf+xml to semantic web programs searching for RDF data. I went with this solution, and it seems to work.

0 Comments:

    Post a Comment