1

I am using Web API to create RESTful services. I decided to using Accept header as a api versioning mechanism by following this implementation. http://blog.maartenballiauw.be/post/2013/03/08/Custom-media-types-for-ASPNET-Web-API-versioning.aspx

Accept: application/json; version=1

For entity standardization and query capabilities, I planned to use Odata. The problem currently I see is that the odata only supports(or only I know) the entity versioning using url.

 modelBuilder1.EntitySet<V1.Product>("Products");
 modelBuilder2.EntitySet<V2.Product>("Products");

 Microsoft.Data.Edm.IEdmModel model1 = modelBuilder1.GetEdmModel();
 Microsoft.Data.Edm.IEdmModel model2 = modelBuilder2.GetEdmModel();

 config.Routes.MapODataRoute("ODataRoute1", "api\v1", model1);
 config.Routes.MapODataRoute("ODataRoute2", "api\v2", model2);

Is there any solution available for to configure odata to consider accept header ?

Thanks in Advance.

1
  • Entityset names cannot have / in them. Commented May 17, 2013 at 5:56

1 Answer 1

2

We have a very good sample on versioning using web API OData. You can find it here

3
  • Thanks. I looked at the solution and it looks promisisng. I will validate and update this thread. In meantime I like to keep this thread open for others answers.
    – Vytheese
    Commented May 20, 2013 at 15:38
  • I am finding a problem in the controller selector provided in the sample solution. When I tried using the version in header. The controller always selects the first registered route. So I am alwyas ending up to the first registered version of the controller.
    – Vytheese
    Commented May 21, 2013 at 16:12
  • @raghuram-nadiminti - I was very happy to find the example and initially it worked great. However, because of the mapping of the ViewModel to the Db Entity, $expand doesn't seem to work. Each version's $metadata shows the navigation properties, they just don't work. Do you know, is it possible to get this working? Commented Dec 9, 2015 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.