1.9.0 • Published 4 years ago

@sap/odata-v4 v1.9.0

Weekly downloads
116
License
SEE LICENSE IN de...
Repository
-
Last release
4 years ago

OData V4.0 Server Library

Table of Contents

Overview

With the OData server library OData V4.0 services can be implemented based on the OASIS OData standard. The library can be directly used to build OData services and is also part of the SAP Fiori programming model as well the SAP Cloud Platform programming model, where the data model can be defined in CDS (Core data services) and the OData service be generated out of the model.

The library leaves the freedom to build OData services with any db or persistence layer. It is also possible to create services, that are calling external REST/OData services and mix up the data with your application data.

The library is modular and consists of the following main components:

  • EntityDataModel - Define your EDM in JSON format. Our provider creates the EDM out of your model and caches EDM model elements
  • Handler Dispatcher - Maps requests to handler functions for CRUD operations
  • URI parsers - Parse the request URI including the OData system query options (like $format, $select, $expand,...) and validates each URI segment against the EDM model and the OData ABNF
  • Serializers and Deserializers for the request and response payload. The deserializers validate the request payload and support type mapping between OData EDM types and JavaScript Types
  • Automatic OData Reponse generation based on provided data
  • ServiceFactory to create the OData service along with the CRUD handler registration
  • Conditional request handling for optimistic concurrency control via ETAGs
  • Batch handling - Batch request parsing, dispatching to single batch requests, Content-ID referencing and batch response generation
  • Flexible API to support all backends - The service developer has the free choice of his backend system (e.g., databases, frameworks, calling additional external OData services).

Installation

npm install @sap/odata-v4

Usage

const odata = require('@sap/odata-v4');
// Load your edm model.
const edmModel = require('./<your_edm_model>.json');

// Create the service
const service = odata.ServiceFactory.createService(edmModel)

    // Register the request handler for CRUD operations
    .on('create', function create(request, response, next){...})
    .on('update', function update(request, response, next){...})
    .on('delete', function delete(request, response, next){...})
    .on('read', function read(request, response, next){...})

//Create the server
const port = 9000;
const server = http.createServer((req, res) => service.process(req, res))
    .listen(port,
        () => console.log(`Server listens on port ${port} - Service URL: http://localhost:${port}/serviceroot.svc/`)
    );

Supported Requests

ResourceRequest
Read RequestGET
ServiceootGET http://host/serviceRoot/
MetadataGET http://host/serviceRoot/$metadata
EntitySetGET http://host/serviceRoot/EntitySet
EntitySetGET http://host/serviceRoot/EntitySet/$count
EntityGET http://host/serviceRoot/EntitySet(Key)
ReferencesGET http://host/serviceRoot/EntitySet/$ref
ReferenceGET http://host/serviceRoot/EntitySet(Key)/$ref
References(related)GET http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToMany/$ref
Reference(related)GET http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToMany/$ref
Related EntityGET http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToOne
Related EntitiesGET http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToMany
Complex PropertyGET http://host/serviceRoot/EntitySet(Key)/ComplexProperty
Complex Property CollectionGET http://host/serviceRoot/EntitySet(Key)/ComplexPropertyCollection
Primitive PropertyGET http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty
Primitive Property ValueGET http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty/$value
Primitive Property CollectionGET http://host/serviceRoot/EntitySet(Key)/PrimitivePropertyCollection
Create/Insert RequestsPOST
EntityPOST http://host/serviceRoot/EntitySet
Deep InsertPOST http://host/serviceRoot/EntitySet
Entity with bind operationsPOST http://host/serviceRoot/EntitySet
ReferencePOST http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToMany/$ref
Update RequestsPUT/PATCH
EntityPUT/PATCH http://host/serviceRoot/EntitySet(Key)
ReferencePUT http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToOne/$ref
Complex PropertyPUT/PATCH http://host/serviceRoot/EntitySet(Key)/ComplexProperty
Complex Property CollectionPUT http://host/serviceRoot/EntitySet(Key)/ComplexPropertyCollection
Primitive PropertyPUT http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty
Primitive Property ValuePUT http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty/$value
Primitive Property CollectionPUT http://host/serviceRoot/EntitySet(Key)/PrimitivePropertyCollection
Delete RequestsDELETE
EntityDELETE http://host/serviceRoot/EntitySet(Key)
ReferenceDELETE http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToOne/$ref
Reference(To Many)DELETE http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToMany(Key)/$ref
Complex PropertyDELETE http://host/serviceRoot/EntitySet(Key)/ComplexProperty
Complex Property CollectionDELETE http://host/serviceRoot/EntitySet(Key)/ComplexPropertyCollection
Primitive PropertyDELETE http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty
Primitive Property ValueDELETE http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty/$value
Primitive Property CollectionDELETE http://host/serviceRoot/EntitySet(Key)/PrimitivePropertyCollection
Actions and FunctionsGET/POST
Function ImportGET http://host/serviceRoot/FunctionImports/Navigation- or PropertyPath
boundFunctionGET http://host/serviceRoot/EntitySet/boundFunction
boundFunctionGET http://host/serviceRoot/EntitySet(Key)/boundFunction
boundFunctionGET http://host/serviceRoot/EntitySet(Key)/ComplexProperty/boundFunction
boundFunctionGET http://host/serviceRoot/EntitySet(Key)/ComplexPropertyCollection/boundFunction
boundFunctionGET http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty/boundFunction
boundFunctionGET http://host/serviceRoot/EntitySet(Key)/PrimitivePropertyCollection/boundFunction
ActionImportPOST http://host/serviceRoot/ActionImport
boundActionPOST http://host/serviceRoot/EntitySet/boundAction
boundActionPOST http://host/serviceRoot/EntitySet(Key)/boundAction
boundActionPOST http://host/serviceRoot/EntitySet(Key)/ComplexProperty/boundAction
boundActionPOST http://host/serviceRoot/EntitySet(Key)/ComplexPropertyCollection/boundAction
boundActionPOST http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty/boundAction
boundActionPOST http://host/serviceRoot/EntitySet(Key)/PrimitivePropertyCollection/boundAction

Supported System Query Options

System Query OptionOASIS OData V4.0 Errata 3 - Query Option Description
$filterSupported values see OASIS specification
$expandSupported values see OASIS specification
$selectSupported values see OASIS specification
$orderbySupported values see OASIS specification
$top and $skipSupported values see OASIS specification
$countSupported values see OASIS specification
$searchSupported values see OASIS specification
$formatSupported values see OASIS specification

Analytical Queries - $apply

TransformationSampleLimitations
aggregateGET ~/Sales?$apply=aggregate(Amount with sum as Total)Keyword 'from' is not supported
topcountGET ~/Sales?$apply=topcount(2,Amount)
topsumGET ~/Sales?$apply=topsum(15,Amount)
toppercentGET ~/Sales?$apply=toppercent(50,Amount)
bottomcountGET ~/Sales?$apply=bottomcount(2,Amount)
bottomsumGET ~/Sales?$apply=bottomsum(7,Amount)
bottompercentGET ~/Sales?$apply=bottompercent(50,Amount)
identityGET ~/Sales?$apply=identity
concatGET ~/Sales?$apply=concat(topcount(2,Amount),aggregate(Amount))
groupbyGET ~/Sales?$apply=groupby((Customer/Country,Product/Name), aggregate(Amount with sum as Total))rollup and $all is not supported
filterGET ~/Sales?$apply=filter(Amount gt 3)
expandNot supported
searchGET ~/Sales?$apply=search(coffee)

Releases and Milestones

Changelog

1.7.0

4 years ago

1.8.0

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.9.0

4 years ago