0.1.3 • Published 8 years ago

odata-v4-resource v0.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

OData V4 Resource

OData v4 resource path handler

Using low-level

createODataPath(exampleUri, metadata): creates an Express route path from an example OData URI

var createServiceOperationCall = require('../lib/index').createServiceOperationCall;
var createODataPath = require('../lib/index').createODataPath;

app.get(createODataPath('/Kittens(1)/Kittens(2)/Default.Rect(id=1)', metadata), function(req, res, next){
	var call = createServiceOperationCall(req.url, metadata);
	res.send(call);
});

Using resource controller

Create a router module:

var express = require('express');
var router = express.Router();

var ODataController = require('../../lib/index').ODataController;
var metadata = require('../metadata');

function MyController(req, res, next){
    this.MySingleton = {
        /* ... */
    };
    this.MyAction = function(){
        /* ... */
        return {
			/* ... */
		};
    };
    this.MyFunction = function(param1, param2){
        /* ... */
        return {
			/* ... */
		};
    };
    this.MyEntitySet = function(key){
        return new Promise(function(resolve, reject){
            var start = Date.now();
            setTimeout(function(){
                resolve({
                    /* ... */
                });
            }, Math.random() * 3000);
        });
    };
    this.$value = function(){
        return { /* ... */ };
    };
    this.$ref = function(){
        /* ... */
    };
}

router.use(ODataController(MyController, metadata));

module.exports = router;

Use your controller router in Express:

app.use('/odata', require('./controllers/MyController'));