W3C home > Mailing lists > Public > public-rdf-ruby@w3.org > May 2010

Linked Data content negotiation for Rack applications

From: Arto Bendiken <arto.bendiken@gmail.com>
Date: Wed, 26 May 2010 14:44:51 +0200
Message-ID: <AANLkTim-T58LaZHq6Y0Ioy5OaFk1MxIfywGOY9L_Bp-N@mail.gmail.com>
To: public-rdf-ruby@w3.org
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

    #!/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!"]

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

    $ 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

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

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 19:53:40 UTC