1.8.3 • Published 4 years ago

@sap/odata-server v1.8.3

Weekly downloads
10,120
License
SEE LICENSE IN de...
Repository
-
Last release
4 years ago

OData V4.0 Server Library

Library is deprecated and will not be further developed and maintained. We recommend to use the SAP Cloud application programming model to build OData Services instead of the 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 database 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-server

Usage

Load the library:

const odata = require('@sap/odata-server');

Load your EDM model:

const edmModel = require('./<your_edm_model>.json');

Create the service, set the base path, and register request handlers for CRUD operations:

const service = odata.ServiceFactory.createService(edmModel)
    .setBasePath('/serviceroot.svc/')
    .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) {...});

You can create an HTTP server locally to test your service:

const http = require('http');
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

Read Requests Using HTTP GET

ResourceRequest
Service rootGET 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 Requests Using HTTP POST

ResourceRequest
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 Requests Using HTTP PUT/PATCH

ResourceRequest
EntityPUT/PATCH http://host/serviceRoot/EntitySet(Key)
Deep updatePUT/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 Requests Using HTTP DELETE

ResourceRequest
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

Functions Using HTTP GET

ResourceRequest
Function importGET http://host/serviceRoot/FunctionImport/Navigation-or-Property-Path
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

Actions Using HTTP POST

ResourceRequest
Action importPOST 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

Analytical queries with $apply are described in the specification for the OData data aggregration extension.

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
computeGET ~/Customers?$apply=compute(length(Country) as Length)
filterGET ~/Sales?$apply=filter(Amount gt 3)
orderbyGET ~/Sales?$apply=orderby(Customer/Name)
expandNot supported
searchGET ~/Sales?$apply=search(coffee)
skipGET ~/Sales?$apply=skip(5)
topGET ~/Sales?$apply=top(4)

Releases and Milestones

Changelog

1.8.3

4 years ago

1.8.2

4 years ago

1.5.5

4 years ago

1.1.0

4 years ago

1.3.8

4 years ago

1.3.3

4 years ago

1.8.0

4 years ago

1.5.1

4 years ago

1.3.7

4 years ago

1.3.9

4 years ago

1.0.0

4 years ago

1.5.2

4 years ago

1.3.4

4 years ago

1.6.0

4 years ago

1.7.1

4 years ago