This is Rack middleware that provides Linked Data content
negotiation for Rack applications. You can use Rack::LinkedData
with any
Ruby web framework based on Rack, including with Ruby on Rails 3.0 and with
Sinatra.
- Implements HTTP content negotiation for RDF content types.
- Supports all RDF.rb-compatible serialization formats.
- Compatible with any Rack application and any Rack-based framework.
# config/application.rb
require 'rack/linkeddata'
class Application < Rails::Application
config.middleware.use Rack::LinkedData::ContentNegotiation
end
#!/usr/bin/env ruby -rubygems
require 'sinatra'
require 'rack/linkeddata'
use Rack::LinkedData::ContentNegotiation
get '/hello' do
RDF::Graph.new do |graph|
graph << [RDF::Node.new, RDF::DC.title, "Hello, world!"]
end
end
#!/usr/bin/env rackup
require 'rack/linkeddata'
rdf = RDF::Graph.new do |graph|
graph << [RDF::Node.new, RDF::DC.title, "Hello, world!"]
end
use Rack::LinkedData::ContentNegotiation
run lambda { |env| [200, {}, rdf] }
use Rack::LinkedData::ContentNegotiation, :default => "text/turtle"
$ rackup doc/examples/hello.ru
$ curl -iH "Accept: text/plain" http://localhost:9292/hello
$ curl -iH "Accept: text/turtle" http://localhost:9292/hello
$ curl -iH "Accept: application/rdf+xml" http://localhost:9292/hello
$ curl -iH "Accept: application/json" http://localhost:9292/hello
$ curl -iH "Accept: application/trix" http://localhost:9292/hello
$ curl -iH "Accept: */*" http://localhost:9292/hello
Rack::LinkedData
implements content negotiation for any Rack response
object that implements the RDF::Enumerable
mixin. You would typically
return an instance of RDF::Graph
or RDF::Repository
from your Rack
application, and let the Rack::LinkedData::ContentNegotiation
middleware
take care of serializing your response into whatever RDF format the HTTP
client requested and understands.
The middleware queries RDF.rb for the MIME content types of known RDF serialization formats, so it will work with whatever serialization plugins that are currently available for RDF.rb. (At present, this includes support for N-Triples, Turtle, RDF/XML, RDF/JSON and TriX.)
http://datagraph.rubyforge.org/rack-linkeddata/
- {Rack::LinkedData}
- {Rack::LinkedData::ContentNegotiation}
- Rack (>= 1.0.0)
- Linked Data (>= 0.3.0)
The recommended installation method is via RubyGems. To install the latest official release of the gem, do:
% [sudo] gem install rack-linkeddata
To get a local working copy of the development repository, do:
% git clone git://github.com/datagraph/rack-linkeddata.git
Alternatively, download the latest development version as a tarball as follows:
% wget http://github.com/datagraph/rack-linkeddata/tarball/master
- http://www.w3.org/DesignIssues/LinkedData.html
- http://linkeddata.org/docs/how-to-publish
- http://linkeddata.org/conneg-303-redirect-code-samples
- http://www.w3.org/TR/cooluris/
- http://www.w3.org/TR/swbp-vocab-pub/
- http://patterns.dataincubator.org/book/publishing-patterns.html
This is free and unencumbered public domain software. For more information, see http://unlicense.org/ or the accompanying {file:UNLICENSE} file.