25

I'm starting a project that has to expose a RESTful service that will be consumed by a wide variety of clients of several OSs.

I'm reading about Web API and OData using Web API and it's hard for me to decide what to use, the plain Web API or the OData one.

What are some notable pros and cons?

Update
Would you guys be kind enough and comment on why this question is "primarily opinion based"? where exactly do you see any personal opinion here?

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
  • 2
    I would UNvote to close if there's an option but we can always Vote to reopen if that reaches that point. I too would like to read here a detailed answer of the pros and cons. The link you provided does not provide much insight to your question. I'll help dig into this when time permits. – von v. Jul 07 '15 at 06:17
  • @vonv. Thanks! I've found a nice article that shed light on the subject, please check out [my answer](http://goo.gl/RLCE4W). Anyway, not related to the question, are you familiar with OData? I'd like to know 1) Does OData provide validation functionality that can work with [DataAnnotations](https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations)? 2) Are there client generators or scaffolding for web-apps, [WUA](https://dev.windows.com/en-us/develop/build-apps-shared-code) etc.? Something like [RIA Services](https://msdn.microsoft.com/en-us/library/ee707344) R.I.P – Shimmy Weitzhandler Jul 07 '15 at 08:15
  • 1
    I actually have no idea @Shimmy and that's the reason I starred this post. I am learning a new thing here as well. – von v. Jul 07 '15 at 08:29
  • I would consider (a true REST) WebAPI an exposer of a 'domain' model (oversimplified analog: database tables, columns with CRUD) . OData provides a query mechanism on top of that (oversimplified analog: T-SQL). Using the OData standard allows for granular selection and retrieval (including references) from the "user of the API" where as with a WebAPI you would have to "make functions" to do 'specific' selects/queries. I do not know, but doubt, Asp.Net MVC control attributes are supported by OData. – Marvin Smit Jul 08 '15 at 07:24
  • @MarvinSmit good point, that might be a boomer. If Razor doesn't support OData I'm gonna stick to plain WebAPI, do you know for sure it's not supported? – Shimmy Weitzhandler Jul 08 '15 at 10:45
  • Wouldn't you mix those? Razor+MVC for your client side views (templates for the client mVvm), OData API for your client side model (accessed through Ajax calls, feeding the mvVM)? – Marvin Smit Jul 08 '15 at 14:42
  • @MarvinSmit although I obviously want to separate the layers as much as possible, I can't afford to rewrite all the entities as View DTOs or in JS/TS. And if Razor scaffolding doesn't support OData generating appropriate views, I have an issue. But reading the OData support in WebAPI [documentation](http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api), I believe it's not a problem. – Shimmy Weitzhandler Jul 09 '15 at 12:09

1 Answers1

4

I've found this great post by Julie Lerman, that explains Web API and OData, and that OData is like a Web API with added a WCF-like feature set.

One of the features is easy prototypes of generic CRUD controllers.
The article is more detailed and clear.

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
  • 1
    I am finding that OData seems to be great for reading data only (the R in CRUD). Because aside from authorization, everything can be handled in the query usually, and if you need something more complex, then exposing OData over WebAPI can still be done (so the complex models are built on the server). Writing/deleting/updating I'm not sure. Because either way, these "events" may not be straight forward. So I don't see OData being useful in this department at all really. – Worthy7 Nov 02 '16 at 02:10
  • 1
    @Worthy7 Technically you're right. Anyway, OData is specifically useful when you want to give the client the freedom in obtaining, refining, filtering ,caching, and sorting the data. – Shimmy Weitzhandler Nov 02 '16 at 15:35
  • I actually did a bit of research and it seems it can be more straightforward than I thought. Using OData Actions/Function, which essentially allow you to run functions which are held server-side. The 'Invoking Bound Actions' sections here: http://www.odata.org/getting-started/basic-tutorial/#operation – Worthy7 Nov 04 '16 at 00:34
  • 9
    I find it strange that Microsoft create all these complex technologies and neglect to make it crystal clear when to use which! – NoChance Jan 03 '18 at 21:30