Posts Tagged ‘JSON’

Put on Your OData Face – Developer Smackdown Episode #23

Monday, April 19th, 2010

Go check out our latest episode where Clark and I talk about OData.

Episode #23: Intro to OData

OData – Getting Started

Friday, March 19th, 2010

Just got back from the MIX10 conference. Hanging out with by buddy Clark Sell and doin podcasts, we took in and tried to absorb as much as we could.  Of course the big news was around Windows Phone 7 Series and Silverlight 4 but there was also quite a buzz about OData.  Personally, the moniker is a little boring but who am I to judge – the capability is the big thing.  If you haven’t heard about it, it is an open protocol for working with ATOM and JSON data feeds.  Just from that description, you might be thinking “so what” – well, keep reading. This protocol isn’t just so you can publish or consume feed data, you know you can do that.  But, now you can output a customizable data feed without knowing the full intention of the consumer ahead of time.  In other words, you can provide a data feed service that can directly respond to the consumer’s requests/queries and output the feed with only the data requested in the way best suited for them to consume and you don’t need a custom set of API endpoints to do it.

OData-logo

Some OData Facts:

  • The OData spec is around the protocol, not the implementation. (BTW, already, there are libraries available for JavaScript, PHP, Java, Objective-C and .NET)
  • It is based on REST calls through HTTP so (GET, PUT, DELETE, POST, etc.) so strictly speaking, you don’t even need a client api to access OData feeds – you could do it from a browser URL/Address line.
  • Feeds can be output in ATOM as well as JSON again, from the same endpoint.
  • The protocol is for reading from AND writing data back to a data source
  • Security around the data can be enforced

Try it:

Go to http://services.odata.org/Northwind/Northwind.svc/

The OData site has provided access to the sample Northwind database. When you get there you will see all of the data that you can access and query against. 

Notice from the result set that there is a list of all the different collections of data that you can access from this single service.  You have Customers, Shippers, Products, Suppliers, Regions, Orders, etc.  All you need to do to access any one of the collections is to type the collection name in the URL.  This example will return a list of all products:

http://services.odata.org/Northwind/Northwind.svc/Products 

Note: at this point things are case-sensitive so “Products” works but “products” won’t.  

image

If you are in Internet Explorer, and don’t see the detailed data stream, you might want to go to “Tools \ Internet Options

\ Content \ Feeds and Web Slices \ Settings”.  Then, uncheck “Turn on feed reading view”.  After that, you will see the actual feed data in the browser.

Cool. But, what if I only want products with a unit price over 50.00?  Add a filter:

http://services.odata.org/Northwind/northwind.svc/Products?$filter=UnitPrice gt 50

Notice that the UnitPrice is typed and is a Decimal.  Others are 16bit integers, 32bit integers, booleans, etc.

Now, sort:

http://services.odata.org/Northwind/northwind.svc/Products?$filter=UnitPrice gt 50&$orderby=UnitPrice

Would you rather the data being sent back be in JSON format?

http://services.odata.org/Northwind/northwind.svc/Products?$filter=UnitPrice gt 50&$orderby=UnitPrice&$format=JSON

All of this is being done through a single endpoint.  Even more important, it is being done with a standard set of query parameters which means that you will know how to publish and consume (i.e., select, extract, filter, sort and format) data coming from any feed that uses the OData Protocol.  Schweeet!

Next up…Create your own publisher with WCF Data Services.

Resources and Info:

Technorati Tags: ,,,
Get Adobe Flash playerPlugin by wpburn.com wordpress themes