Git Product home page Git Product logo

odata_server's Introduction

OData Server

This is a rails plugin/engine to embue your application with OData features (so its data can be readily consumed by an OData client).

In OData, a service exposes a number of workspace. Each workspace is backed by a schema and contains a collection of entity collections. An entity collection is a related set of records.

Configure the plugin by adding a number of schema objects to OData::Edm::DataServices.schemas. Each schema is an instance of a subclass of OData::AbstractSchema::Base. We currently only support two implementations, and the specific implementation determines how to load the records, mapping the records' properties to/from Edm data types, and handling filtering, sorting, and data retrieval.

  • OData::ActiveRecordSchema::Base -- either you give it a list or it iterate over all your models exposing each as OData entities

and

  • OData::InMemorySchema::Base -- this takes in a list of objects which are exposed as OData entities

The accessible OData service will be a read-only provider.

This code is not heavily tested. It is alpha quality at best. Expect the API to change drastically over time.

Resources

OData V4:

Dependencies

Rails 4 or higher.

Installation

Put this line in your Gemfile:

gem 'odata_server'

Run the bundle command to install it.

Then add the following lines to an initializer (ex: odata_server.rb):

# ActiveRecordSchema

ar_schema = OData::ActiveRecordSchema::Base.new('AR', classes: Foo)
OData::Edm::DataServices.schemas << ar_schema

# OR

OData::Edm::DataServices.schemas << OData::ActiveRecordSchema::Base.new

By giving a list of classes to ActiveRecordSchema, it will represent only theses classes. Without classes option, all the models will be represented. ActiveRecordSchema can take a reflection option too (default is false): if true the models associations will be shown.

# InMemorySchema

class Foo
  attr_reader :foo, :bar, :baz

  def initialize(foo, bar, baz)
    @foo = foo
    @bar = bar
    @baz = baz
  end
end

inmem = OData::InMemorySchema::Base.new("InMem", classes: Foo)
OData::Edm::DataServices.schemas << inmem
(1..20).each do |n|
  inmem.find_entity_type("Foo").entities.append(Foo.new(n, "test", "test #{n}"))
end

ActiveRecordSchema and InMemorySchema can either take a single classe or an array of classes.

Then, mount the OData::Engine in routes.rb:

mount OData::Engine, at: '/service/OData'

Restart your sever and you can visit the /service/Odata url that is the service base.

See https://github.com/lmcalpin/odata_provider_example_rb for an example application that uses this gem.

TODOS

  • Update the core for OData v4
  • Add support for $search option
  • Update and add more tests

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.