Linked Data content negotiation for Rack applications

As a follow-up to the `linkeddata` metadistribution of RDF.rb, I have
also just released a first rough cut of the `rack-linkeddata` gem [1].

This gem is intended to provide a standard Linked Data content
negotiation component for any Rack-compatible Ruby web applications
(this includes e.g. all Rails 3.x and Sinatra applications), removing
the need for these applications to concern themselves with either RDF
serialization or HTTP header parsing.

Rack::LinkedData was inspired by and intended for Nicholas Humfrey's
work with DBpedia lite [2], which is to be a first testing grounds for
the gem.

You can install the gem as follows:

    $ sudo gem install rack-linkeddata

Using Rack::LinkedData in a Sinatra [3] application is particularly
straightforward. Here follows a minimal complete RDF-based "Hello,
world!" application [4] using Ruby, RDF.rb, Sinatra and
Rack::LinkedData:

    #!/usr/bin/env ruby -rubygems
    require 'sinatra'
    require 'rack/linkeddata'

    use Rack::LinkedData::ContentNegotiation

    get '/hello' do
      RDF::Graph.new do
        self << [RDF::Node.new, RDF::DC.title, "Hello, world!"]
      end
    end

Given its brevity, it's probably self-evident what this application is
supposed to do, even if you're not familiar with Sinatra or RDF.rb.

If you have Sinatra installed, you can run this example application as follows:

    $ ruby -rubygems hello.rb

After Sinatra boots up (on port 4567 by default), you can use `curl`,
or a similar tool like `wget` and `fetch`, to test out the content
negotiation:

    $ curl -iH "Accept: text/plain" http://localhost:4567/hello
    $ curl -iH "Accept: text/turtle" http://localhost:4567/hello
    $ curl -iH "Accept: application/rdf+xml" http://localhost:4567/hello
    $ curl -iH "Accept: application/json" http://localhost:4567/hello
    $ curl -iH "Accept: application/trix" http://localhost:4567/hello
    $ curl -iH "Accept: */*" http://localhost:4567/hello

...and so on - you get the idea. Some more details can be found in the
README [5].

This Rack middleware is going to be deployed on a number of production
sites over the next few days, which should work out any kinks it still
has. It's our hope that it will in time become a dependable and easy
way to plug in Linked Data content negotiation into any Rails
application in particular.

-- 
Arto Bendiken | http://datagraph.org/

[1] http://rubygems.org/gems/rack-linkeddata
[2] http://dbpedialite.org/
[3] http://www.sinatrarb.com/
[4] http://github.com/datagraph/rack-linkeddata/blob/master/doc/examples/hello.rb
[5] http://github.com/datagraph/rack-linkeddata

Received on Wednesday, 26 May 2010 12:45:26 UTC