Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webApi2 Odata v3 and V4 side by side

How can I have odata v3 and v4 api working side by side out on the same project ?

Can the same controller be returning data in both formats ? Do I need to have 2 copies of the same controller - one per Odata version ?

I know this should be possible cause the official WEBAPI page says it's been designed for.

"ASP.NET Web API supports both v3 and v4 of the protocol. You can even have a v4 endpoint that runs side-by-side with a v3 endpoint." - quote from www.asp.net

Question is - how do I do that ? Any tutorials ?

like image 524
Marty Avatar asked Sep 04 '14 12:09

Marty


People also ask

What is OData v4?

The Open Data Protocol (OData) enables the creation of REST-based data services, which allow resources, identified using Uniform Resource Locators (URLs) and defined in an Entity Data Model (EDM), to be published and edited by Web clients using simple HTTP messages.

What is OData in Web API 2?

The Open Data Protocol (OData) is a data access protocol for the web. OData provides a uniform way to query and manipulate data sets through CRUD operations (create, read, update, and delete). ASP.NET Web API supports both v3 and v4 of the protocol.

What is Odataqueryoptions?

OData defines parameters that can be used to modify an OData query. The client sends these parameters in the query string of the request URI. For example, to sort the results, a client uses the $orderby parameter: http://localhost/Products?$orderby=Name. The OData specification calls these parameters query options.


2 Answers

Here is a sample for side by side: https://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v4/ODataSxSSample/, FYI. This sample has 2 copies of the same controller.

like image 71
Tan Jinfu Avatar answered Oct 15 '22 08:10

Tan Jinfu


Yes, you do need two set of controllers. V4 doesn't provide backward compatibility.

There is also another sample for versioning: https://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v4/ODataVersioningSample/

This is the right solution for you. You make the first version (~/api/v1/) for OData V3 and the second version (~api/v2/) for V4. It provides better separation.

like image 44
maomao Avatar answered Oct 15 '22 07:10

maomao