odata-v4-resource
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

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'));

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.30latest

Version History

VersionDownloads (Last 7 Days)Published
0.1.30
0.1.20
0.1.10
0.1.00

Package Sidebar

Install

npm i odata-v4-resource

Weekly Downloads

0

Version

0.1.3

License

MIT

Last publish

Collaborators

  • lazarv