{"id":1013,"date":"2011-02-08T20:41:00","date_gmt":"2011-02-08T20:41:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/odatateam\/2011\/02\/08\/new-javascript-library-for-odata-and-beyond\/"},"modified":"2011-02-08T20:41:00","modified_gmt":"2011-02-08T20:41:00","slug":"new-javascript-library-for-odata-and-beyond","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/odata\/new-javascript-library-for-odata-and-beyond\/","title":{"rendered":"New JavaScript library for OData and beyond"},"content":{"rendered":"<p class=\"MsoNormal\"><span style=\"color: #1f497d\"><span style=\"font-size: small\"><span style=\"font-family: Calibri\">Today we are announcing a new project called &lsquo;datajs&rsquo;, 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. &lsquo;datajs&rsquo; 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&#8217;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. <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"color: #1f497d\"><span style=\"font-family: Calibri;font-size: small\">&nbsp;<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small\"><span style=\"font-family: Calibri\"><span style=\"color: #1f497d\">The library is developed as an open source project with the help from OData community. Please visit the project <\/span><span style=\"color: black\"><a href=\"https:\/\/datajs.codeplex.com\/\">CodePlex page<\/a> <\/span><span style=\"color: #1f497d\">to review code files, samples, documentation,&nbsp;and for any feedback or design recommendations. <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Calibri;font-size: small\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><b><span style=\"color: #1f497d\"><span style=\"font-size: small\"><span style=\"font-family: Calibri\">OData.read<\/span><\/span><\/span><\/b><\/p>\n<p class=\"MsoNormal\"><span style=\"color: #1f497d\"><span style=\"font-size: small\"><span style=\"font-family: Calibri\">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.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">OData.read(&#8220;<span style=\"color: #0000ff\">http:\/\/odata.netflix.com\/v1\/Catalog\/Genres<\/span>&#8220;, function (data, response) {<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">\/\/success handler<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"color: #1f497d\"><span style=\"font-family: Calibri;font-size: small\">&nbsp;<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><b><span style=\"color: #1f497d\"><span style=\"font-size: small\"><span style=\"font-family: Calibri\">OData.request<\/span><\/span><\/span><\/b><\/p>\n<p class=\"MsoNormal\"><span style=\"color: #1f497d\"><span style=\"font-size: small\"><span style=\"font-family: Calibri\">The &lsquo;request&rsquo; 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. <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"color: #1f497d\"><span style=\"font-size: small\"><span style=\"font-family: Calibri\">Example:<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"color: #1f497d\"><span style=\"font-family: Calibri;font-size: small\">&nbsp;<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">OData.request({<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">&nbsp;&nbsp;&nbsp; method: &#8220;POST&#8221;,<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">&nbsp;&nbsp;&nbsp; requestUri: &#8220;<span style=\"color: #0000ff\">http:\/\/ODataServer\/FavoriteMovies.svc\/BestMovies<\/span>&#8220;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">&nbsp;&nbsp;&nbsp; data: {ID: 0, MovieTitle: &#8216;Up&#8217;}<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">}, <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">function (data, response) {<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">&nbsp;&nbsp;&nbsp; \/\/success handler<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">});<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"color: #1f497d\"><span style=\"font-family: Calibri;font-size: small\">&nbsp;<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">OData.request({<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">&nbsp;&nbsp;&nbsp; method: &#8220;DELETE&#8221;,<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">&nbsp;&nbsp;&nbsp; requestUri: <span style=\"color: #0000ff\">&#8220;<span style=\"color: #0000ff\">http:\/\/ODataServer\/FavoriteMovies.svc\/BestMovies(<\/span>&#8220;0&#8221;)&#8221;<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">}, <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">function (data, response) {<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">&nbsp;&nbsp;&nbsp; \/\/success handler<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: #1f497d;font-size: 10pt\">});<\/span><span style=\"color: #1f497d\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"color: #1f497d\"><span style=\"font-family: Calibri;font-size: small\">&nbsp;<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small\"><span style=\"font-family: Calibri\"><span style=\"color: #1f497d\">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&nbsp;with a custom HTTP client, similarly one can also define custom handlers to process specific data types. Visit<\/span> <\/span><\/span><a href=\"https:\/\/datajs.codeplex.com\/\"><span style=\"font-family: Calibri;font-size: small\">datajs CodePlex page<\/span><\/a><span style=\"font-size: small\"><span style=\"font-family: Calibri\"> <span style=\"color: #1f497d\">for more detailed documentation.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small\"><span style=\"font-family: Calibri\"><span style=\"color: #1f497d\">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.<\/p>\n<p><b>datajs Team<\/b><br \/><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"color: #1f497d\"><span style=\"font-family: Calibri;font-size: small\">&nbsp;<\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we are announcing a new project called &lsquo;datajs&rsquo;, 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. &lsquo;datajs&rsquo; is an open source project, released under MIT. In this initial release, the library offers basic functionality [&hellip;]<\/p>\n","protected":false},"author":512,"featured_media":3253,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[41,48],"class_list":["post-1013","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-odata","tag-javascript","tag-odata"],"acf":[],"blog_post_summary":"<p>Today we are announcing a new project called &lsquo;datajs&rsquo;, 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. &lsquo;datajs&rsquo; is an open source project, released under MIT. In this initial release, the library offers basic functionality [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/1013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/users\/512"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/comments?post=1013"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/1013\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media\/3253"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media?parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/categories?post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/tags?post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}