Search code examples
web-servicesasp.net-web-apiodataasp.net-web-api2

Why a web API should be OData enabled?


I am creating a web API to extract data from SAP service. My Team lead has asked me to make a odata enabled web API. I read few articles but there is no strong reason which can tell that odata has great advantage if we are consuming an asmx service into web API which in turn will be used by Sharepoint client.


Solution

  • There are a couple of reasons why I'd recommend to choosing OData over general WebApi:

    1. OData provide a level of discoverability that is not present out of the box with a generic WebApi solution. For example, if you have an entity "Widget", one can query the Odata root and it will be listed, along with all the other entities you've exposed. I can tell you from experience, going back to a WebApi project and trying to remember what everything is called is a pain, and this really helps.
    2. OData provide a level of basic queryability without having to with a bunch of plumbing code. If you want to filter you widget's by color, you don't need to write a bunch of code to pass this down to your data layer, just add something to the querystring, e.g. "$fitler=color eq 'red'". Works with paging, etc., as well. Along with this, it is relatively easy to place limits (e.g. max number of results), to prevent a host of issues.