JavaScript REST – Why Use OData When JSON is Available?

javascriptjsonrest

I am trying to understand the point of Odata and when it would make sense. Right now how I work is I use ASP.NET and MVC/WebApi controller to serialize/deserialize objects into JSON and have javascript do something with it.

From what I can tell the benefit of OData is being able to query directly from the URL … But since I am writing the client and server code there is no need for that.

Would anyone ever parse the results of a ODaya query in javascript??

Maybe OData is more about providing a generic endpoint for ALL clients to get detailed information from a query that JSON does not provide ? So if I was a provider of data then I suppose that is what odata is for ?

Help me understand the purpose and use of REST/JSON/ODATA.

Best Answer

JSON is just a data-interchange format based on JavaScript.

REST is an architecture style whereas OData is a specific implemenation of REST designed to generate and consume data, which supports two formats, AtomPub and JSON.

So the difference between JSON with plain REST and OData are the options in OData for data manipulation eg, if we query data using OData protocol, we can specify the below options in the URI,

  • $orderby
  • $top
  • $skip
  • $filter
  • $format
  • $select

We can do projection, link the resources, etc. and all these options are available out of the box. Now imagine if we had to provide all these features in our own REST service then we would have to,

  • Implement all of them
  • Create our own convention/keywords for different operations

It is not only lot of work but also leads to inconsistencies and creates a learning curve for our data consumers.