Jaa


New JavaScript library for OData and beyond

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("https://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: "https://ODataServer/FavoriteMovies.svc/BestMovies"

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

},

function (data, response) {

    //success handler

});

 

OData.request({

    method: "DELETE",

    requestUri: "https://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

Comments

  • Anonymous
    February 09, 2011
    is this not just the reminence of the Microsft Ajax Library? Why not just use jQuery?

  • Anonymous
    February 09, 2011
    Chris, this release of datajs is focused on providing first-class support for OData. As such, it works stand-alone without requiring any additional libraries, provides additional flexibility in how the protocol is handled, and supports a wider array of protocol features (eg, multiple content types and property mappings).The intent isn't to replace these libraries, which are really good at what they do, but instead to provide building blocks that will work well with them.

  • Anonymous
    February 09, 2011
    This is fantastic news! A JS-native client library will help my clients develop applications faster with my OData products. Thanks and great work!

  • Anonymous
    April 18, 2012
    How is this related to UpshotJS?

  • Anonymous
    May 16, 2012
    Hey Guys! I just want to share my very positive feedback, because the idea and the implementation of data.js is outstanding. We included it in our JayData library (http://jaydata.codeplex.com), it took only few days to implement the OData provider to our client-side, LINQ-like data management tool and we were able to easily hide the query building and transport layer. The OData provider is only a part of our concept (we support SQLite, IndexedDb and YQL with the same syntax), but data.js was really helpful the ship a productive tool to developers. Implementing a Northwind product editor in JavaScript and HTML5 now takes only 6 minutes: www.youtube.com/watch I'm looking forward to seeing more useful tools like data.js! Nice job!

  • Anonymous
    June 24, 2012
    this request method is giving an error.. http request failed

  • Anonymous
    July 04, 2012
    How the transaction will be maintained while performing CRUD operation with OData ?