Example code for doing HTTP content negotiation for Linked Data in Ruby on Rails
Ruby JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
config
doc
public
script
test
MIT-LICENSE
README
Rakefile

README

Ruby on Rails Linked Data content negotiation skeleton code.
============================================================

This is a complete (though very simple!) Ruby on Rails application (version 2.3.2). The only non-standard files are the following:

- app/controllers/resources_controller.rb - This is the file that actually does the content negotiation, using the standard Rails 'respond_to' method.    
- config/environment.rb - includes the definition of the application/rdf+xml MIME type and maps it to the .rdf extension.
- config/routes.rb - maps URLs of the form <domain>/resources/<id> to the 'show' action of 'resources_controller'
- app/views/resources/show.erb - to generate the HTML representation of a resource (dummy code only)
- app/views/resources/show.rxml - to generate the RDF representaiton of a resource (dummy code only)


This example assumes the following approach to URIs:

http://<my domain>/resources/<resource_name>   - URI for the resource
http://<my domain>/resources/<resource_name>.html - HTML description of the resource
http://<my domain>/resources/<resource_name>.rdf - RDF description of the resource


To run the application you will need to set up an empty MySQL database called 'conneg_development' with user 'root' and password 'admin' or of course adapt the file config/database.yml to match your own choices for database name and account details.

To check if it is working: 
--------------------------
1. run the app in development mode 
2. In your browser, enter the url http://localhost:3000/resources/test1
3. You should be redirected to http://localhost:3000/resources/test1.html and see the text "HTML description of the resource here."
4. In your browser, enter the url http://localhost:3000/resources/test1.rdf - you should see some valid RDF
5. From the command line (on Unix like systems) enter:
          curl -v -H "Accept: application/rdf+xml" http://localhost:3000/resources/test1
You should get a response like this:

> GET /resources/test1 HTTP/1.1
> User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3
> Host: localhost:3000
> Accept: application/rdf+xml
> 
< HTTP/1.1 303 See Other
< Connection: close
< Date: Mon, 06 Jul 2009 10:05:18 GMT
< X-Runtime: 3
< Location: http://localhost:3000/resources/test1.rdf
< Content-Type: application/rdf+xml; charset=utf-8
< Cache-Control: no-cache
< Content-Length: 107
< 



Any questions, contact me at bill@swirrl.com

Bill Roberts, 06 July, 2009.

The code in this example is released under the MIT license http://www.opensource.org/licenses/mit-license.php
Copyright (c) 2009, Swirrl IT Ltd., http://www.swirrl.com