Calling OData actions and service operations with JayData

Most of the OData examples and applications operate with EntitySets, which is a very flexible way for data collaboration if we want the client applications to implement the business logic. OData service operations, entity-level and entityset-level actions provide us the opportunity to centralize some of our business logic and encapsulate the code on the server-side. The OData standard defines the way you can can consume these services and JayData library helps you to access these remote functions from JavaScript in a comfortable way.

Setting up the OData context for JayData

A context object must be initialized in order to initialize the connection with the remote endpoint and generate the client-side “proxy classes” for data access; JayData provides a static and a dynamic alternative to do so, both of them are based on the $metadata of the service.

Including the necessary libraries

JayData has no external dependency, but the OData provider is using the datajs library and we want to use promises in our code, which we will achieve by leveraging jQuery promises.

Static context initialization

Static context initialization requires to run the JaySvcUtil.exe, which generates a JavaScript file with the necessary data model and metadata. Including this file make you able to initialize the context with the following snippet:

Dynamic context initialization

The dynamic context creation comes handy if you want to avoid re-generating the entity definitions from time-to-time and you know the schema of you published service.
With $data.initService() you can be sure that you are using the up-to-date model as it is generated from the service metadata. But this requires the $metadata document to be accessible from the origin of your app.

Publishing operations and actions on the server-side

You might ask the way of publishing OData service operations and actions, but at this moment I cannot tell you a server-side technology, which implements both… nevertheless, JayData library is ready to consume the upcoming releases of WCF Data Services and WebAPI OData. MS guys are working hard and releasing new versions regularly, we will update this thread with the outcomes. Until then, here are the current options: Service operations can be published with WCF Data Services (.NET), JayData server (node.js) or JayStorm Platform as a Service (cloud), actions can be implemented using WebAPI OData.

Get JayData

JayData on the Social Networks

Copyright JayStack Technologies co. Ltd. 2012.-2018. All Rights Reserved - Privacy policy
Non-JayStack logos/trademarks are copyright to their respective owners and do not constitute an endorsement of any JayStack products.