Giter VIP home page Giter VIP logo

sinatra-rdf's Introduction

Linked Data Content Negotiation for Sinatra Applications

This is a Sinatra extension that provides Linked Data content negotiation for Sinatra applications.

This version is based on [rack-linkeddata][] without the hard dependency on the [linkeddata][] gem, to allow applications to better manage their dependencies

Gem Version Build Status Gitter chat

Features

  • Implements HTTP content negotiation for RDF content types using the [Rack::RDF][Rack::RDF] middleware.
  • Supports all RDF.rb -compatible serialization formats.
  • Supports both classic and modular Sinatra applications.

Examples

Adding Linked Data content negotiation to a classic Sinatra application

#!/usr/bin/env ruby -rubygems
require 'sinatra'
require 'sinatra/rdf'

get '/hello' do
  RDF::Graph.new do |graph|
    graph << [RDF::Node.new, RDF::DC.title, "Hello, world!"]
  end
end

Adding Linked Data content negotiation to a modular Sinatra application

#!/usr/bin/env ruby -rubygems
require 'sinatra/base'
require 'sinatra/rdf'

module My
  class Application < Sinatra::Base
    register Sinatra::RDF

    get '/hello' do
      RDF::Graph.new do |graph|
        graph << [RDF::Node.new, RDF::DC.title, "Hello, world!"]
      end
    end
  end
end

My::Application.run! :host => '127.0.0.1', :port => 4567

Adding Linked Data content negotiation to a Rackup application

#!/usr/bin/env rackup
require 'sinatra/base'
require 'sinatra/rdf'

module My
  class Application < Sinatra::Base
    register Sinatra::RDF

    get '/hello' do
      RDF::Graph.new do |graph|
        graph << [RDF::Node.new, RDF::DC.title, "Hello, world!"]
      end
    end
  end
end

run My::Application

Testing Linked Data content negotiation using rackup and curl

$ rackup doc/examples/config.ru

$ curl -iH "Accept: application/n-triples" http://localhost:9292/hello
$ curl -iH "Accept: application/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

Description

Sinatra::RDF is a thin Sinatra-specific wrapper around the [Rack::RDF][Rack::RDF] middleware, which implements Linked Data content negotiation for Rack applications.

At the moment the Sinatra extension simply corresponds to doing the following manually in a Sinatra application:

require 'rack/rdf'

module My
  class Application < Sinatra::Base
    use     Rack::RDF::ContentNegotiation
    helpers Sinatra::RDF::Helpers
    include ::RDF
  end
end

See the Rack::RDF documentation for more information on the operation and details of the content negotiation.

Documentation

Dependencies

Installation

The recommended installation method is via RubyGems. To install the latest official release of the gem, do:

% [sudo] gem install sinatra-rdf

Download

To get a local working copy of the development repository, do:

% git clone git://github.com/ruby-rdf/sinatra-rdf.git

Alternatively, you can download the latest development version as a tarball as follows:

% wget https://github.com/ruby-rdf/sinatra-rdf/tarball/master

References

Authors

License

Sinatra::RDF is free and unencumbered public domain software. For more information, see https://unlicense.org/ or the accompanying UNLICENSE file.

sinatra-rdf's People

Contributors

gkellogg avatar

Watchers

Arto Bendiken avatar  avatar Chris Beer avatar Aymeric Brisse avatar David Butler avatar Julien Pervillé avatar James Cloos avatar Dorian Taylor avatar tamsin woo avatar  avatar

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.