Today we are announcing a new project called ‘datajs’, a cross-browser JavaScript library that enables web applications to do more with data. datajs leverages modern protocols such as JSON and OData as well as HTML5-enabled browser features. ‘datajs’ is an open source project, released under MIT. In this initial release, the library offers basic functionality to communicate with OData services. The library supports receiving data and submitting changes, using both the JSON and ATOM-based formats. The API can be made aware of metadata in cases where it's required, and operations can be batched to minimize round-trips. We plan to extend the level of functionality in this area, as well as provide additional APIs to work with local data through modern HTML5 features such as IndexedDB as they become available in popular web browsers.

 

The library is developed as an open source project with the help from OData community. Please visit the project CodePlex page to review code files, samples, documentation, and for any feedback or design recommendations.

 

OData.read

You can use OData.read to get data from a OData service end point. For example you can get all available Genres in the Netflix service by making the following call.

OData.read("http://odata.netflix.com/v1/Catalog/Genres", function (data, response) {

//success handler

       });

 

OData.request

The ‘request’ API is used for add, update and delete operations. OData.request can be used with a request that includes the POST, PUT or DELETE methods and an object on which the operation is performed. Library take cares of serializing it into the correct format.

Example:

 

OData.request({

    method: "POST",

    requestUri: "http://ODataServer/FavoriteMovies.svc/BestMovies"

    data: {ID: 0, MovieTitle: 'Up'}

},

function (data, response) {

    //success handler

});

 

OData.request({

    method: "DELETE",

    requestUri: "http://ODataServer/FavoriteMovies.svc/BestMovies("0")"

},

function (data, response) {

    //success handler

});

 

Metadata is optional for many scenarios, but it can be used to improve how server values are interpreted and annotated in their in-memory representations. The library also support batch operations, as defined by the OData protocol . A batch request groups multiple operations into a single HTTP POST request. Refer to datajs documentation for more details. Library can also be customized for more advanced scenarios. For example the library lets you replace the defaultHttpClient with a custom HTTP client, similarly one can also define custom handlers to process specific data types. Visit datajs CodePlex page for more detailed documentation.

 

Over time we plan to evolve datajs into a comprehensive library that can be used to develop rich data-centric web applications. It is designed to be small, fast, and provide functionality for structured queries, synchronization, data modification, and interaction with various cloud services, including Windows Azure. Microsoft is committed to deliver a JavaScript library that utilizes Cloud computing and modern HTML5 features in order to fulfill the needs of the emerging market for powerful data-centric Web applications.

datajs Team