Although I am new to the OData protocol and OData reporting, I am realizing that the more I learn about it, the more I like it.
OData allows anyone to query data from a REST API by supplying typed data as well as relevant metadata. Armed with this information, one can easily and quickly write a client simply by looking and drilling down on the metadata for the specific information needed.
URI Syntax Matters
The URI syntax is critical to get back the exact results you want. Let me show you what I mean.
Let’s start the Service Root URL:
Notice we receive a list of entity sets: Photos, People, Airlines, Airports and Me along with some other data. The information returned is useful but quite limited and high level. Now let’s try the same service root URL, but this time let’s add ~/$metadata at the end to request the metadata for that service root URL.
Notice the difference in the amount of data returned. You will also notice that the return payload is now in XML instead of JSON. OData can return output in either format. You now have all of the metadata as well as the data types listed out for you. With this information, you can write whatever query you wish.
OData Query Example
Let’s say you want to see a list of the entities located under entity set “People”. You could ask for this information with the following query:
You can even narrow your results down to an individual entity by entity ID like this:
Another way you can narrow down results is by using $filter. Here is an example:
And here is a short video going over the basics of OData and discussing another way to interact with OData, which I find more user-friendly:
Learn More About OData Reporting
This is just the tip of the iceberg. There is a tremendous amount of flexibility in the OData standard for querying data if you care to digest the documentation .
Author: Luis Hernandez
Luis is an honorably discharged US Army veteran with 15 years of IT experience and has filled engineering roles for companies including IBM, Hewlett-Packard and McGraw-Hill. When not researching/learning about the next big thing in technology, Luis enjoys making glass art, participating in IDPA competitive shooting events and exploring the Colorado Rockies in his Harley Davidson motorcycle.
Other posts by Luis Hernandez