Skip to content

Instantly share code, notes, and snippets.

@njh
Created May 26, 2010 09:31
Show Gist options
  • Save njh/414277 to your computer and use it in GitHub Desktop.
Save njh/414277 to your computer and use it in GitHub Desktop.
Example of using Sinatra and Spira with Rack::LinkedData for content negotiation.
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
require 'spira'
require 'rack/linkeddata'
use Rack::LinkedData::ContentNegotiation, :default => 'text/turtle'
include RDF
# FIXME: why is this needed?
Spira.add_repository! :default, Repository.new
class Person
include Spira::Resource
property :name, :predicate => FOAF.name, :type => String
property :homepage, :predicate => FOAF.homepage
end
njh = Person.new(
RDF::URI('http://www.aelius.com/njh#me'),
:name => 'Nicholas Humfrey',
:homepage => URI('http://www.aelius.com/njh/')
)
get '/njh' do
njh
end
# Then try:
#
# curl -H 'Accept: text/turtle' http://127.0.0.1:4567/njh
# curl -H 'Accept: application/rdf+xml' http://127.0.0.1:4567/njh
# curl -H 'Accept: application/json' http://127.0.0.1:4567/njh
#
# or
#
# curl -H 'Accept: application/rdf+xml;q=0.1,text/plain' http://127.0.0.1:4567/njh
#
@njh
Copy link
Author

njh commented May 26, 2010

Rack::LinkedData is super-cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment