GithubHelp home page GithubHelp logo

swirrl / contentnegotiation Goto Github PK

View Code? Open in Web Editor NEW
13.0 12.0 1.0 157 KB

Example code for doing HTTP content negotiation for Linked Data in Ruby on Rails

Home Page: http://www.swirrl.com

License: MIT License

JavaScript 1.11% Ruby 98.89%

contentnegotiation's Introduction

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 [email protected]

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

contentnegotiation's People

Contributors

billswirrl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

kublaj

contentnegotiation's Issues

Help in HTTP/1.1 303 See Other

When I go command line (on Unix like systems) enter:

curl -v -H "Accept: ap://0.0.0.0:3000/projetos/unix

  • About to connect() to 0.0.0.0 port 3000 (#0)
  • Trying 0.0.0.0...
  • Connected to 0.0.0.0 (0.0.0.0) port 3000 (#0)

    GET /projetos/unix HTTP/1.1
    User-Agent: curl/7.29.0
    Host: 0.0.0.0:3000
    Accept: application/rdf+xml

    < HTTP/1.1 303 See Other
    < Location: http://0.0.0.0:3000/projetos/unix.rdf
    < Content-Type: application/rdf+xml; charset=utf-8
    < X-Ua-Compatible: IE=Edge
    < Cache-Control: no-cache
    < X-Request-Id: 511ab1105d69248cec53efb63f44815a
    < X-Runtime: 1.892727
    < Server: WEBrick/1.3.1 (Ruby/1.9.3/2013-05-15)
    < Date: Fri, 25 Apr 2014 22:14:24 GMT
    < Content-Length: 103
    < Connection: Keep-Alive
    <
  • Connection #0 to host 0.0.0.0 left intact You are being redirected.

But not redirect ,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.