OData: The Open Data Protocol

Mike asked me to write something about OData for this week’s MSDN Flash Newsletter – reproducing that below – mostly just a bit of fun as it’s hard to fit anything into these short articles.

It’s hard to write an article to teach you anything about OData in 500 words. Why set out on that journey when we can do something “less boring instead”;

Run up your browser. I recommend IE8 as it seems to have most control around viewing raw XML but you can use “View Source” in FireFox or Chrome.

Remember in IE8 to switch off the lipstick that it applies to ATOM/RSS data by using the following menu options;

Tools | Internet Options | Content | Feeds and Web Slices | Settings | Feed Reading View OFF

Point it at http://odata.netflix.com/Catalog (the Netflix movie catalog in OData format)

Notice that the default XML namespace is the open standard ATOM Publishing Protocol

Query for Movie People: http://odata.netflix.com/Catalog/People.

Notice that the default XML namespace is the open standard ATOM XML format

Double extra bonus points for spotting that it is supplemented with elements from the Open Data Protocol published under Microsoft’s Open Specification Promise

Scroll down to the bottom and notice that the data is being paged by the server – if you’re feeling adventurous, follow the hyperlink to the next page of data (the one with $skiptoken). If you’re got some time to kill, keep following those “next” links for a few hours Smile

Try to locate Nicole Kidman:


Too many Kidmans? Choose the top record:


Not perhaps the best way of finding Nicole (‘Papa?’), use the primary key instead:


Which films has Nicole been in? Who could forget the classic “Days of Thunder” with Tom Cruise as “Cole Trickle”:


What if I wanted Nicole’s info as well as the titles she’s acted in?:


Too much data? Sort these titles alphabetically and return the first page of data for a page size of 3:


But to do paging I’ll be needing the total record count (notice m:count element with value 47):


Next page:


Prefer JSON? Well, there’s no accounting for taste but I know “Cole Trickle” preferred it too:


Getting a feel for it? It’s not just about querying though…

OData is a web protocol based on open standards for RESTful querying and modification of exposed collections of data. It takes the basics of REST and adds mechanisms for addressing, metadata, batching, and data representation using HTTP, AtomPub, Atom and JSON.

Want to expose OData endpoints? See here. There is support in a number of products and also in .NET Framework (V3.5 Sp1 onwards) for easily exposing OData endpoints from standard data models such as those provided by Entity Framework and also from custom data models provided by your own code.

Want to consume OData endpoints? See here. There are client libraries for all kinds of clients including AJAX, full .NET, Silverlight and Windows Phone 7.

Either way, go here and watch Pablo explain it more fully (double-click the video once you’ve started it playing as no-one can be expected to watch a video playing in a 1.5inch square Smile)